From 025e1851eda7f99b50bd8e4dcb0da42811846c6a Mon Sep 17 00:00:00 2001 From: cnYui Date: Tue, 9 Jun 2026 12:02:35 +0900 Subject: [PATCH] fix: include service in dynamic help usage --- .changeset/fix-help-usage-service-path.md | 5 +++ crates/google-workspace-cli/src/commands.rs | 35 +++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .changeset/fix-help-usage-service-path.md diff --git a/.changeset/fix-help-usage-service-path.md b/.changeset/fix-help-usage-service-path.md new file mode 100644 index 00000000..8a7a2c3c --- /dev/null +++ b/.changeset/fix-help-usage-service-path.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +Include the service name in dynamic command help usage paths. diff --git a/crates/google-workspace-cli/src/commands.rs b/crates/google-workspace-cli/src/commands.rs index 27324e42..f67d5fd2 100644 --- a/crates/google-workspace-cli/src/commands.rs +++ b/crates/google-workspace-cli/src/commands.rs @@ -18,11 +18,17 @@ use crate::discovery::{RestDescription, RestResource}; /// Builds the full CLI command tree from a Discovery Document. pub fn build_cli(doc: &RestDescription) -> Command { + build_cli_for_service(doc, &doc.name) +} + +/// Builds the full CLI command tree with the user-facing service name in help usage. +pub fn build_cli_for_service(doc: &RestDescription, service_name: &str) -> Command { let about_text = doc .description .clone() .unwrap_or_else(|| "Google Workspace CLI".to_string()); let mut root = Command::new("gws") + .bin_name(format!("gws {service_name}")) .about(about_text) .subcommand_required(true) .arg_required_else_help(true) @@ -279,4 +285,33 @@ mod tests { "--sanitize arg should be present on root command" ); } + + #[test] + fn test_help_usage_includes_service_name() { + let doc = make_doc(); + + let service_help = build_cli(&doc) + .try_get_matches_from(["gws", "--help"]) + .unwrap_err(); + assert_eq!(service_help.kind(), clap::error::ErrorKind::DisplayHelp); + let service_help = service_help.to_string(); + assert!( + service_help.contains("Usage: gws drive [OPTIONS] "), + "{service_help}" + ); + + let resource_help = build_cli(&doc) + .try_get_matches_from(["gws", "files", "--help"]) + .unwrap_err(); + assert_eq!(resource_help.kind(), clap::error::ErrorKind::DisplayHelp); + let resource_help = resource_help.to_string(); + assert!( + resource_help.contains("Usage: gws drive files [OPTIONS] "), + "{resource_help}" + ); + assert!( + !resource_help.contains("Usage: gws files [OPTIONS] "), + "{resource_help}" + ); + } }