Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add Cargo.lock to project template to avoid broken dependencies #191

Merged
merged 3 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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