Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 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
56ddeff
fix ui tests
ElijahAhianyo Aug 16, 2026
3d9ad2f
fix dependency mess(hopefully)
ElijahAhianyo Aug 16, 2026
9336b24
normalize path separator dor windows
ElijahAhianyo Aug 16, 2026
8387bc9
fix docstring. Temporarily revert request ui tests to see if CI passes
ElijahAhianyo Aug 16, 2026
5bfe9fd
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 16, 2026
ac5f8bc
adding some debug statements to instrument windows CI failure
ElijahAhianyo Aug 16, 2026
5e7f46f
Merge remote-tracking branch 'origin/elijah/cot-proxy-cmd' into elija…
ElijahAhianyo Aug 16, 2026
abe2318
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 16, 2026
6acd271
should compile now
ElijahAhianyo Aug 16, 2026
f6fcd3d
Merge remote-tracking branch 'origin/elijah/cot-proxy-cmd' into elija…
ElijahAhianyo Aug 16, 2026
ffe7e72
isolating tests
ElijahAhianyo Aug 16, 2026
6590dc1
see if windows test gets fixed
ElijahAhianyo Aug 16, 2026
3669369
try to build if bin not found
ElijahAhianyo Aug 17, 2026
d51c000
chore(pre-commit.ci): auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 17, 2026
5a6f0f2
use status so child forwards to parent on windows. see if it works
ElijahAhianyo Aug 17, 2026
e0cc344
Merge remote-tracking branch 'origin/elijah/cot-proxy-cmd' into elija…
ElijahAhianyo Aug 17, 2026
afc507e
fix miri tests. Also a couple of improvements
ElijahAhianyo Aug 17, 2026
d2a8549
fix docs test
ElijahAhianyo Aug 17, 2026
43d79ce
address roughly 85% of comments
ElijahAhianyo Aug 20, 2026
12c56a2
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Aug 20, 2026
7716b12
address 2 more comments
ElijahAhianyo Aug 20, 2026
73ae4ef
add some tests to handle target-dir discovery
ElijahAhianyo Aug 21, 2026
d8dcb36
normalize path in windows to fix tests
ElijahAhianyo Aug 21, 2026
edea1c3
fix flaky tests
ElijahAhianyo Aug 21, 2026
b32dc83
fix help tests
ElijahAhianyo Aug 21, 2026
a98e8e8
miri ignore
ElijahAhianyo Aug 21, 2026
b510092
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Aug 25, 2026
e099107
Merge branch 'master' into elijah/cot-proxy-cmd
ElijahAhianyo Aug 25, 2026
f0486dc
Merge remote-tracking branch 'origin/elijah/cot-proxy-cmd' into elija…
ElijahAhianyo Aug 25, 2026
515cab1
clippy fix
ElijahAhianyo Aug 25, 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
334 changes: 186 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ backtrace = "0.3.76"
blake3 = "1.8.5"
bytes = "1.12"
cargo_toml = "1.0"
cargo_metadata = "0.23.1"
chrono = { version = "0.4.45", default-features = false }
chrono-tz = { version = "0.10", default-features = false }
clap = { version = "4.6", features = ["deprecated"] }
Expand Down Expand Up @@ -144,7 +145,7 @@ subtle = { version = "2", default-features = false }
swagger-ui-redist = { version = "0.1" }
syn = { version = "3", default-features = false }
sync_wrapper = "1"
tempfile = "3"
tempfile = "3.11"
thiserror = "2"
time = { version = "0.3.55", default-features = false }
tokio = { version = "1.53", default-features = false }
Expand All @@ -157,6 +158,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
12 changes: 10 additions & 2 deletions cot-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ workspace = true

[dependencies]
anyhow.workspace = true
assert_cmd = { workspace = true, optional = true }
cargo_toml.workspace = true
cargo_metadata.workspace = true
chrono.workspace = true
clap = { workspace = true, features = ["derive", "env", "wrap_help", "string"] }
clap_complete.workspace = true
Expand All @@ -41,14 +43,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"
]
111 changes: 111 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,89 @@ 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> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also handle cases like cot check -- -p package here? (and if so, we should have tests for these as well)

@ElijahAhianyo ElijahAhianyo Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called in main() after we split on -- to differentiate internal args from args forwarded to the binary. In practice, it wouldn't receive raw args, but I've added a defensive check to the function to handle that case.

Also, shouldn't this be cot check -p package instead of cot check -- -p package? I'd imagine that external args (args after the -- delimiter) are forwarded to the binary, so we should expect this to throw an error.

That also brings me to this scenario: commands like migration rollback, collect-static, and check live in the binary and are treated as external commands from the perspective of cot-cli, just like custom commands. However, we market these commands as first-class cot-cli commands to end users. So users would expect all cot commands to follow the same convention, with args coming before the delimiter, rather than having to figure out which internal commands require args after the delimiter and which require args before.

I think as a follow-up to this PR, we should have some mechanism to make cot-cli aware of what commands to treat as first-class citizens, and also maybe a way to make CliTask aware of flags already registered by cot-cli (like --package and --release).

What do you think?

let mut iter = raw.iter();
while let Some(arg) = iter.next() {
if arg == "--" {
// all args before the double dash delimeter is used internally per convention
// and any arg after the delimeter is forwarded to the binary, so we
// stop here
return None;
}
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);
}

#[test]
fn extract_package_arg_stops_scanning_at_double_dash() {
let raw = args(&["cot", "check", "--", "-p", "package"]);
assert_eq!(extract_package_arg(&raw), None);
}

#[test]
fn extract_package_arg_found_before_double_dash_ignores_forwarded_content() {
let raw = args(&["cot", "-p", "real", "check", "--", "-p", "forwarded"]);
assert_eq!(extract_package_arg(&raw), Some("real".to_string()));
}
}
Loading
Loading