Skip to content

Commit 92e66a3

Browse files
Justin Poehneltjpoehnelt-bot
andauthored
feat: add gws version bare subcommand (npm#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>
1 parent 680b60c commit 92e66a3

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

.changeset/version-subcommand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@googleworkspace/cli": patch
3+
---
4+
5+
Add `gws version` as a bare subcommand alongside `gws --version` and `gws -V`

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
1313
## Build & Test
1414

15+
> [!IMPORTANT]
16+
> **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.
17+
1518
```bash
1619
cargo build # Build in dev mode
1720
cargo clippy -- -D warnings # Lint check

src/main.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ async fn run() -> Result<(), GwsError> {
6868
let first_arg = &args[1];
6969

7070
// Handle --help and --version at top level
71-
if first_arg == "--help" || first_arg == "-h" {
71+
if is_help_flag(first_arg) {
7272
print_usage();
7373
return Ok(());
7474
}
7575

76-
if first_arg == "--version" || first_arg == "-V" {
76+
if is_version_flag(first_arg) {
7777
println!("gws {}", env!("CARGO_PKG_VERSION"));
7878
return Ok(());
7979
}
@@ -399,6 +399,14 @@ fn print_usage() {
399399
println!(" Please search existing issues first; if one already exists, comment there.");
400400
}
401401

402+
fn is_help_flag(arg: &str) -> bool {
403+
matches!(arg, "--help" | "-h")
404+
}
405+
406+
fn is_version_flag(arg: &str) -> bool {
407+
matches!(arg, "--version" | "-V" | "version")
408+
}
409+
402410
#[cfg(test)]
403411
mod tests {
404412
use super::*;
@@ -480,6 +488,24 @@ mod tests {
480488
assert_eq!(config.mode, helpers::modelarmor::SanitizeMode::Block);
481489
}
482490

491+
#[test]
492+
fn test_is_version_flag() {
493+
assert!(is_version_flag("--version"));
494+
assert!(is_version_flag("-V"));
495+
assert!(is_version_flag("version"));
496+
assert!(!is_version_flag("--ver"));
497+
assert!(!is_version_flag("v"));
498+
assert!(!is_version_flag("drive"));
499+
}
500+
501+
#[test]
502+
fn test_is_help_flag() {
503+
assert!(is_help_flag("--help"));
504+
assert!(is_help_flag("-h"));
505+
assert!(!is_help_flag("help"));
506+
assert!(!is_help_flag("--h"));
507+
}
508+
483509
#[test]
484510
fn test_resolve_method_from_matches_basic() {
485511
let mut resources = std::collections::HashMap::new();

0 commit comments

Comments
 (0)