Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Declare shell value names directly on CLI arguments (#4554)
Maximilian Roos1347baefcee8
diff --git a/src/cli/config.rs b/src/cli/config.rsindex 7fc8b09be..e399116c4 100644--- a/src/cli/config.rs+++ b/src/cli/config.rs@@ -62,7 +62,7 @@ Invoke-Expression (& wt config shell init powershell | Out-String))]Init {/// Shell to generate code for- #[arg(value_enum)]+ #[arg(value_enum, value_name = super::shell_value_name())]shell: Shell,/// Command name for shell integration (defaults to binary name)@@ -95,7 +95,7 @@ Use --yes to skip confirmation."#)]Install {/// Shell to install (default: all)- #[arg(value_enum)]+ #[arg(value_enum, value_name = super::shell_value_name())]shell: Option<Shell>,/// Show what would be changed@@ -140,7 +140,7 @@ Uninstall removes every worktrunk-managed integration it finds, regardless of:)]Uninstall {/// Shell to uninstall (default: all)- #[arg(value_enum)]+ #[arg(value_enum, value_name = super::shell_value_name())]shell: Option<Shell>,/// Show what would be changeddiff --git a/src/cli/mod.rs b/src/cli/mod.rsindex eeb66b9e3..3ce6cab3c 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -96,12 +96,9 @@ Usage: {usage}{all-args}{after-help}";-/// Cached value_name for Shell enum (e.g., "bash|fish|zsh|powershell")-///-/// TODO: There should be a simpler way to show ValueEnum variants in clap's "missing required-/// argument" error. Clap auto-generates `[possible values: ...]` in help and completions from-/// ValueEnum, but doesn't use it for value_name. We use mut_subcommand to set it dynamically,-/// but this feels overly complex. Revisit if clap adds better support.+/// Shell variants for usage and missing-argument errors, shared by the shell+/// argument declarations. Clap's ValueEnum shows possible values in help but+/// does not include them in the usage placeholder by default.fn shell_value_name() -> &'static str {static CACHE: OnceLock<String> = OnceLock::new();CACHE@@ -118,21 +115,7 @@ fn shell_value_name() -> &'static str {/// Build a clap Command for Cli with the shared help template applied recursively.pub(crate) fn build_command() -> Command {- let cmd = apply_help_template_recursive(Cli::command(), DEFAULT_COMMAND_NAME);-- // Set value_name for Shell args to show options in usage/errors- let shell_name = shell_value_name();- cmd.mut_subcommand("config", |c| {- c.mut_subcommand("shell", |c| {- c.mut_subcommand("init", |c| c.mut_arg("shell", |a| a.value_name(shell_name)))- .mut_subcommand("install", |c| {- c.mut_arg("shell", |a| a.value_name(shell_name))- })- .mut_subcommand("uninstall", |c| {- c.mut_arg("shell", |a| a.value_name(shell_name))- })- })- })+ apply_help_template_recursive(Cli::command(), DEFAULT_COMMAND_NAME)}/// Parent commands whose subcommands can be suggested for unrecognized top-level commands.diff --git a/src/main.rs b/src/main.rsindex 4adf8c748..87dd71e44 100644--- a/src/main.rs+++ b/src/main.rs@@ -790,11 +790,6 @@ fn parse_cli() -> Cli {// Exits the process on a help/version/doc request; otherwise returns.help::maybe_handle_help_with_pager(alias_help_context, subcommand.as_deref());- // TODO: Enhance error messages to show possible values for missing enum arguments- // Currently `wt config shell init` doesn't show available shells, but `wt config shell init invalid` does.- // Clap doesn't support this natively yet - see https://github.com/clap-rs/clap/issues/3320- // When available, use built-in setting. Until then, could use try_parse() to intercept- // MissingRequiredArgument errors and print custom messages with ValueEnum::value_variants().let cmd = cli::build_command();let matches = cmd.try_get_matches_from(std::env::args_os())