Skip to content

Commit

Permalink
fix: add Cargo.lock to project template to avoid broken dependencies
Browse files Browse the repository at this point in the history
By pinning new project's dependencies to specific versions, we avoid
problems like #187 which are caused by changes in the dependencies
(in this case we were using a prerelease version of a dependency which
updated one of its dependencies to edition=2024, but this will also
prevent accidental semver-breaking changes from breaking our builds,
too).

This also adds a justfile that makes it easy to update the lockfile.
  • Loading branch information
m4tx committed Feb 23, 2025
1 parent 6f9e4fb commit 0fcf37b
Show file tree
Hide file tree
Showing 4 changed files with 3,003 additions and 8 deletions.
24 changes: 18 additions & 6 deletions cot-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod utils;
use std::path::PathBuf;

use anyhow::Context;
use clap::{Parser, Subcommand};
use clap::{Args, Parser, Subcommand};
use clap_verbosity_flag::Verbosity;
use tracing_subscriber::util::SubscriberInitExt;

Expand All @@ -32,9 +32,8 @@ enum Commands {
/// Set the resulting crate name (defaults to the directory name)
#[arg(long)]
name: Option<String>,
/// Use the latest `cot` version from git instead of a published crate
#[arg(long)]
use_git: bool,
#[command(flatten)]
source: CotSourceArgs,
},
/// Generate migrations for a Cot project
MakeMigrations {
Expand All @@ -51,6 +50,17 @@ enum Commands {
},
}

#[derive(Debug, Args)]
#[group(multiple = false)]
struct CotSourceArgs {
/// Use the latest `cot` version from git instead of a published crate
#[arg(long, group = "cot_source")]
use_git: bool,
/// Use `cot` from the specified path instead of a published crate
#[arg(long, group = "cot_source")]
cot_path: Option<PathBuf>,
}

fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

Expand All @@ -66,7 +76,7 @@ fn main() -> anyhow::Result<()> {
Commands::New {
path,
name,
use_git,
source: cot_source,
} => {
let project_name = match name {
None => {
Expand All @@ -78,8 +88,10 @@ fn main() -> anyhow::Result<()> {
Some(name) => name,
};

let cot_source = if use_git {
let cot_source = if cot_source.use_git {
CotSource::Git
} else if let Some(path) = &cot_source.cot_path {
CotSource::Path(path)
} else {
CotSource::PublishedCrate
};
Expand Down
4 changes: 2 additions & 2 deletions cot-cli/src/new_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ macro_rules! project_file {
};
}

const PROJECT_FILES: [(&str, &str); 9] = [
const PROJECT_FILES: [(&str, &str); 10] = [
project_file!("Cargo.toml.template"),
project_file!("Cargo.lock.template"),
project_file!("bacon.toml"),
project_file!(".gitignore"),
project_file!("src/main.rs"),
Expand All @@ -28,7 +29,6 @@ const PROJECT_FILES: [(&str, &str); 9] = [
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CotSource<'a> {
Git,
#[allow(dead_code)] // used in integration tests
Path(&'a Path),
PublishedCrate,
}
Expand Down
Loading

0 comments on commit 0fcf37b

Please sign in to comment.