Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fc8f8f1
consolidate cot cli commands into one
ElijahAhianyo Jun 10, 2026
683b2a6
remove dead code
ElijahAhianyo Jun 11, 2026
8a0c6b8
- improve error messages.
ElijahAhianyo Jun 18, 2026
2a4bfba
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Jun 18, 2026
d73cd10
unit tests initial
ElijahAhianyo Jun 23, 2026
219d898
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Jun 23, 2026
0cfd155
some minor refactor
ElijahAhianyo Jun 23, 2026
9beb8ea
fix clippy
ElijahAhianyo Jun 23, 2026
48353cb
fix the snapshot tests
ElijahAhianyo Jun 23, 2026
00016d3
gate unix::process::CommandExt behind unix flag
ElijahAhianyo Jun 23, 2026
7f85e45
fix exec error on windows
ElijahAhianyo Jun 23, 2026
86cfd37
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Jun 23, 2026
9c9b467
make serde_json a required dep
ElijahAhianyo Jun 23, 2026
4e7b5d6
comment improve
ElijahAhianyo Jun 25, 2026
ea45e71
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Jun 25, 2026
464b3c0
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Jul 21, 2026
8001727
update lock files
ElijahAhianyo Jul 21, 2026
0412722
update snapshots
ElijahAhianyo Jul 21, 2026
99ff86e
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Aug 4, 2026
29ade27
fix merge conflicts
ElijahAhianyo Aug 4, 2026
84d8f10
Merge branch 'master' into elijah/cot-proxy-cmd
m4tx Aug 9, 2026
51b6c20
address PR comments. Also some refactor and fixed loads of bugs to im…
ElijahAhianyo Aug 12, 2026
b02da44
comment improve
ElijahAhianyo Aug 12, 2026
545e976
Add test harness
ElijahAhianyo Aug 12, 2026
ca25425
rename project harness for consistency
ElijahAhianyo Aug 12, 2026
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
33 changes: 18 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ tracing-subscriber = "0.3"
tracing-test = "0.2"
trybuild = { version = "1", features = ["diff"] }
url = "2"
wait-timeout = { version = "0.2", default-features = false }

[profile.dev.package]
insta.opt-level = 3
Expand Down
11 changes: 9 additions & 2 deletions cot-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ workspace = true

[dependencies]
anyhow.workspace = true
assert_cmd = {workspace = true, optional = true}
cargo_toml.workspace = true
chrono.workspace = true
clap = { workspace = true, features = ["derive", "env", "wrap_help", "string"] }
Expand All @@ -41,14 +42,20 @@ quote.workspace = true
syn.workspace = true
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true}
wait-timeout = { workspace = true }
tempfile = {workspace = true, optional = true}

[dev-dependencies]
cot-cli = { path = ".", features = ["test_utils"] }
assert_cmd.workspace = true
insta.workspace = true
insta-cmd.workspace = true
tempfile.workspace = true

trybuild.workspace = true

[features]
test_utils = []
test_utils = [
"dep:tempfile"
]
93 changes: 93 additions & 0 deletions cot-cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use std::ffi::OsString;
use std::path::PathBuf;

use clap::{Args, Parser, Subcommand};
use clap_verbosity_flag::Verbosity;

pub const PACKAGE_LONG_FLAG: &str = "--package";
pub const PACKAGE_SHORT_FLAG: &str = "-p";
pub const RELEASE_FLAG: &str = "--release";
pub const HELP_LONG_FLAG: &str = "--help";
pub const HELP_SHORT_FLAG: &str = "-h";
pub const BINARY_FLAG: &str = "--bin";
pub const BUILD_FLAG: &str = "--build";

#[derive(Debug, Parser)]
#[command(
name = "cot",
Expand All @@ -11,6 +20,16 @@ use clap_verbosity_flag::Verbosity;
long_about = None
)]
pub struct Cli {
/// Use target/release instead of target/debug when looking for the project
/// binary
#[arg(long, global = true)]
release: bool,
/// Build the binary if it does not exist
#[arg(long, global = true)]
build: bool,
/// Package to use, in case you're running this in a workspace
#[arg(short = 'p', long, global = true, value_name = "PACKAGE")]
pub package: Option<String>,
#[command(flatten)]
pub verbose: Verbosity,
#[command(subcommand)]
Expand All @@ -29,6 +48,9 @@ pub enum Commands {
/// Manage Cot CLI
#[command(subcommand)]
Cli(CliCommands),

#[command(external_subcommand)]
External(Vec<OsString>),
}

#[derive(Debug, Args)]
Expand All @@ -50,6 +72,9 @@ pub enum MigrationCommands {
Make(MigrationMakeArgs),
/// Create a new empty migration
New(MigrationNewArgs),
/// External migration subcommands shipped with the cot binary
#[command(external_subcommand)]
External(Vec<OsString>),
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -119,3 +144,71 @@ pub struct CompletionsArgs {
/// Shell to generate completions for
pub shell: clap_complete::Shell,
}

/// Pulls `-p <name>` / `--package <name>` / `--package=<name>` out of raw
/// argv, before clap has parsed anything. Needed because `project::load`
/// must run before `Cli::parse` for the `--help` interception path.
#[must_use]
pub fn extract_package_arg(raw: &[String]) -> Option<String> {
let mut iter = raw.iter();
while let Some(arg) = iter.next() {
if let Some(value) = arg.strip_prefix(&format!("{PACKAGE_LONG_FLAG}=")) {
return Some(value.to_string());
}
if arg == PACKAGE_LONG_FLAG || arg == PACKAGE_SHORT_FLAG {
return iter.next().cloned();
}
}
None
}

#[cfg(test)]
mod tests {
use super::*;

fn args(raw: &[&str]) -> Vec<String> {
raw.iter().map(|arg| (*arg).to_string()).collect()
}

#[test]
fn extract_package_arg_long_with_separate_value() {
let raw = args(&["cot", "--release", "--package", "blog", "check"]);

assert_eq!(extract_package_arg(&raw), Some("blog".to_string()));
}

#[test]
fn extract_package_arg_long_with_equals_value() {
let raw = args(&["cot", "--package=blog", "check"]);

assert_eq!(extract_package_arg(&raw), Some("blog".to_string()));
}

#[test]
fn extract_package_arg_short_with_value() {
let raw = args(&["cot", "-p", "blog", "check"]);

assert_eq!(extract_package_arg(&raw), Some("blog".to_string()));
}

#[test]
fn extract_package_arg_returns_first_package_flag() {
let raw = args(&["cot", "-p", "first", "--package", "second", "check"]);

assert_eq!(extract_package_arg(&raw), Some("first".to_string()));
}

#[test]
fn extract_package_arg_missing_value_returns_none() {
let raw = args(&["cot", "check", "-p"]);

assert_eq!(extract_package_arg(&raw), None);
}

#[test]
fn extract_package_arg_absent_returns_none() {
let raw = args(&["cot", "--release", "check"]);

assert_eq!(extract_package_arg(&raw), None);
}
}
Loading
Loading