feat: add gws version bare subcommand (#71)

* feat: add `gws version` bare subcommand

* refactor: extract help and version flag checks into dedicated functions and add test coverage guidance to AGENTS.md

---------

Co-authored-by: jpoehnelt-bot <jpoehnelt-bot@users.noreply.github.com>
This commit is contained in:
Justin Poehnelt
2026-03-04 16:29:02 -07:00
committed by GitHub
parent 680b60cecc
commit 92e66a308f
3 changed files with 36 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---
Add `gws version` as a bare subcommand alongside `gws --version` and `gws -V`
+3
View File
@@ -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
+28 -2
View File
@@ -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();