diff --git a/.changeset/version-subcommand.md b/.changeset/version-subcommand.md new file mode 100644 index 0000000..e8a6d33 --- /dev/null +++ b/.changeset/version-subcommand.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +Add `gws version` as a bare subcommand alongside `gws --version` and `gws -V` diff --git a/AGENTS.md b/AGENTS.md index 01dc207..0cd41e4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,6 +12,9 @@ ## Build & Test +> [!IMPORTANT] +> **Test Coverage**: The `codecov/patch` check requires that new or modified lines are covered by tests. When adding code, extract testable helper functions rather than embedding logic in `main`/`run` where it's hard to unit-test. Run `cargo test` locally and verify new branches are exercised. + ```bash cargo build # Build in dev mode cargo clippy -- -D warnings # Lint check diff --git a/src/main.rs b/src/main.rs index 460a81b..62ef488 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,12 +68,12 @@ async fn run() -> Result<(), GwsError> { let first_arg = &args[1]; // Handle --help and --version at top level - if first_arg == "--help" || first_arg == "-h" { + if is_help_flag(first_arg) { print_usage(); return Ok(()); } - if first_arg == "--version" || first_arg == "-V" { + if is_version_flag(first_arg) { println!("gws {}", env!("CARGO_PKG_VERSION")); return Ok(()); } @@ -399,6 +399,14 @@ fn print_usage() { println!(" Please search existing issues first; if one already exists, comment there."); } +fn is_help_flag(arg: &str) -> bool { + matches!(arg, "--help" | "-h") +} + +fn is_version_flag(arg: &str) -> bool { + matches!(arg, "--version" | "-V" | "version") +} + #[cfg(test)] mod tests { use super::*; @@ -480,6 +488,24 @@ mod tests { assert_eq!(config.mode, helpers::modelarmor::SanitizeMode::Block); } + #[test] + fn test_is_version_flag() { + assert!(is_version_flag("--version")); + assert!(is_version_flag("-V")); + assert!(is_version_flag("version")); + assert!(!is_version_flag("--ver")); + assert!(!is_version_flag("v")); + assert!(!is_version_flag("drive")); + } + + #[test] + fn test_is_help_flag() { + assert!(is_help_flag("--help")); + assert!(is_help_flag("-h")); + assert!(!is_help_flag("help")); + assert!(!is_help_flag("--h")); + } + #[test] fn test_resolve_method_from_matches_basic() { let mut resources = std::collections::HashMap::new();