Skip to content

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

feat: Apply different help templates for commands

Maximilian Roosd95ff95c6cfb
diff --git a/src/cli.rs b/src/cli.rs
index 4cc21b36b..783fee345 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -43,6 +43,8 @@ fn help_styles() -> Styles {
/// Default command name for worktrunk
const DEFAULT_COMMAND_NAME: &str = "wt";
+
+/// Help template for commands without subcommands
const HELP_TEMPLATE: &str = "\
{before-help}{name} - {about-with-newline}\
Usage: {usage}
@@ -50,6 +52,17 @@ Usage: {usage}
Options:
{options}{after-help}";
+/// Help template for commands with subcommands
+const HELP_TEMPLATE_WITH_SUBCOMMANDS: &str = "\
+{before-help}{name} - {about-with-newline}\
+Usage: {usage}
+
+Commands:
+{subcommands}
+
+Options:
+{options}{after-help}";
+
/// Build a clap Command for Cli with the shared help template applied recursively.
pub fn build_command() -> Command {
let cmd = Cli::command();
@@ -57,7 +70,13 @@ pub fn build_command() -> Command {
}
fn apply_help_template_recursive(mut cmd: Command) -> Command {
- cmd = cmd.help_template(HELP_TEMPLATE);
+ let template = if cmd.get_subcommands().next().is_some() {
+ HELP_TEMPLATE_WITH_SUBCOMMANDS
+ } else {
+ HELP_TEMPLATE
+ };
+ cmd = cmd.help_template(template);
+
for sub in cmd.get_subcommands_mut() {
let sub_cmd = std::mem::take(sub);
let sub_cmd = apply_help_template_recursive(sub_cmd);
@@ -302,7 +321,7 @@ pub enum Commands {
/// Manage configuration
#[command(
- about = "Manage configuration. For AI commit setup, run: `wt config --help` (see 'LLM SETUP GUIDE').",
+ about = "Manage configuration",
after_long_help = r#"LLM SETUP GUIDE:
Enable AI-generated commit messages
diff --git a/tests/snapshots/integration__integration_tests__help__help_beta.snap b/tests/snapshots/integration__integration_tests__help__help_beta.snap
index d21c82995..cbff00f89 100644
--- a/tests/snapshots/integration__integration_tests__help__help_beta.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_beta.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
@@ -16,6 +16,16 @@ exit_code: 0
wt-beta - Development and testing utilities
Usage: wt beta [OPTIONS] <COMMAND>
+Commands:
+ run-hook Run project hook
+ commit Commit changes with LLM-generated message
+ squash Squash commits with LLM-generated message
+ push Push changes to target branch
+ rebase Rebase onto target
+ ask-approvals Store approvals in config
+ clear-approvals Clear approved commands from config
+ select Interactive worktree selector
+
Options:
-C <path>
Change working directory
diff --git a/tests/snapshots/integration__integration_tests__help__help_config.snap b/tests/snapshots/integration__integration_tests__help__help_config.snap
index f539d76b6..e8846c820 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config.snap
@@ -8,15 +8,21 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
----- stdout -----
-wt-config - Manage configuration. For AI commit setup, run: wt config --help
-(see 'LLM SETUP GUIDE').
+wt-config - Manage configuration
Usage: wt config [OPTIONS] <COMMAND>
+Commands:
+ init Initialize global configuration file with examples
+ list List configuration files & locations
+ refresh-cache Refresh default branch from remote
+ shell Configure shell integration
+ status Manage branch status markers
+
Options:
-C <path>
Change working directory
diff --git a/tests/snapshots/integration__integration_tests__help__help_init.snap b/tests/snapshots/integration__integration_tests__help__help_init.snap
index 7d30e2962..b41d0696a 100644
--- a/tests/snapshots/integration__integration_tests__help__help_init.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_init.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__help__help_merge.snap b/tests/snapshots/integration__integration_tests__help__help_merge.snap
index 862488718..1a0a4be54 100644
--- a/tests/snapshots/integration__integration_tests__help__help_merge.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_merge.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove.snap b/tests/snapshots/integration__integration_tests__help__help_remove.snap
index b8840e7bc..1a498758f 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__help__help_root.snap b/tests/snapshots/integration__integration_tests__help__help_root.snap
index 821cc302d..8465b4246 100644
--- a/tests/snapshots/integration__integration_tests__help__help_root.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_root.snap
@@ -7,7 +7,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
@@ -15,6 +15,14 @@ exit_code: 0
wt - Git worktree management
Usage: wt [OPTIONS] <COMMAND>
+Commands:
+ init Generate shell integration code
+ config Manage configuration
+ list List worktrees and optionally branches
+ switch Switch to a worktree
+ remove Remove worktree and branch
+ merge Merge worktree into target branch
+
Options:
-C <path>
Change working directory
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch.snap b/tests/snapshots/integration__integration_tests__help__help_switch.snap
index 2080889ff..903e32164 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
- GIT_CONFIG_GLOBAL: ""
+ GIT_EDITOR: ""
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index d10ad90e9..4dc4ded3f 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -19,7 +19,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpFcnCHf/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpmxQ2Xu/test-config.toml
---
success: true
exit_code: 0
@@ -192,7 +192,7 @@ complete -c wt -n "__fish_wt_needs_command" -s v -l verbose -d 'Show commands an
complete -c wt -n "__fish_wt_needs_command" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_needs_command" -s V -l version -d 'Print version'
complete -c wt -n "__fish_wt_needs_command" -f -a "init" -d 'Generate shell integration code'
-complete -c wt -n "__fish_wt_needs_command" -f -a "config" -d 'Manage configuration. For AI commit setup, run: `wt config --help` (see \'LLM SETUP GUIDE\').'
+complete -c wt -n "__fish_wt_needs_command" -f -a "config" -d 'Manage configuration'
complete -c wt -n "__fish_wt_needs_command" -f -a "beta" -d 'Development and testing utilities'
complete -c wt -n "__fish_wt_needs_command" -f -a "list" -d 'List worktrees and optionally branches'
complete -c wt -n "__fish_wt_needs_command" -f -a "switch" -d 'Switch to a worktree'
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index d33d3c996..7e2d323bb 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -15,10 +15,11 @@ info:
GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
GIT_CONFIG_VALUE_0: "false"
+ GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp8OQXUV/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpcO3S47/test-config.toml
---
success: true
exit_code: 0
@@ -498,7 +499,7 @@ esac
_wt_commands() {
local commands; commands=(
'init:Generate shell integration code' \
-'config:Manage configuration. For AI commit setup, run\: \`wt config --help\` (see '\''LLM SETUP GUIDE'\'').' \
+'config:Manage configuration' \
'beta:Development and testing utilities' \
'list:List worktrees and optionally branches' \
'switch:Switch to a worktree' \