Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Add shell value_name to config shell subcommands

Maximilian Roosa3a340617f56
diff --git a/src/cli.rs b/src/cli.rs
index 51a535108..53b7c6004 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -60,9 +60,43 @@ 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.
+fn shell_value_name() -> &'static str {
+ static CACHE: OnceLock<String> = OnceLock::new();
+ CACHE
+ .get_or_init(|| {
+ Shell::value_variants()
+ .iter()
+ .filter_map(|v| v.to_possible_value())
+ .map(|v| v.get_name().to_owned())
+ .collect::<Vec<_>>()
+ .join("|")
+ })
+ .as_str()
+}
+
/// Build a clap Command for Cli with the shared help template applied recursively.
pub fn build_command() -> Command {
- apply_help_template_recursive(Cli::command(), DEFAULT_COMMAND_NAME)
+ 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))
+ })
+ })
+ })
}
fn apply_help_template_recursive(mut cmd: Command, path: &str) -> Command {
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index b641b53f0..37eb5e267 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -68,7 +68,7 @@ fn test_init_invalid_shell(repo: TestRepo) {
----- stdout -----
----- stderr -----
- error: invalid value 'invalid-shell' for '<SHELL>'
+ error: invalid value 'invalid-shell' for '<bash|fish|zsh|powershell>'
[possible values: bash, fish, zsh, powershell]
For more information, try '--help'.