Skip to content

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

Add custom help styles to CLI output

Maximilian Roosfe3131f061ed
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6f2c23fbf..50b4ba7e5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -56,7 +56,7 @@ repos:
language: pygrep
types: ["rust"]
entry: '\\x1b\['
- exclude: '^(tests/|.*_test\.rs$|src/styling/(line|mod)\.rs$|src/output/directive\.rs$)'
+ exclude: '^(tests/|.*_test\.rs$|src/styling/(line|mod)\.rs$|src/output/directive\.rs$|src/cli\.rs$)'
ci:
# Currently network access isn't supported in the CI product.
diff --git a/src/cli.rs b/src/cli.rs
index 7b29b9b80..3aa9acd28 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,9 +1,46 @@
+use clap::builder::styling::{AnsiColor, Color, Styles};
use clap::{Parser, Subcommand};
use std::sync::OnceLock;
use worktrunk::HookType;
use crate::commands::Shell;
+/// Custom styles for help output - matches worktrunk's color scheme
+fn help_styles() -> Styles {
+ Styles::styled()
+ .header(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Green))),
+ )
+ .usage(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Green))),
+ )
+ .literal(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Cyan))),
+ )
+ .placeholder(anstyle::Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan))))
+ .error(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Red))),
+ )
+ .valid(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Green))),
+ )
+ .invalid(
+ anstyle::Style::new()
+ .bold()
+ .fg_color(Some(Color::Ansi(AnsiColor::Yellow))),
+ )
+}
+
/// Default command name for worktrunk
const DEFAULT_COMMAND_NAME: &str = "wt";
@@ -34,6 +71,7 @@ pub enum OutputFormat {
#[command(about = "Git worktree management", long_about = None)]
#[command(version = version_str())]
#[command(disable_help_subcommand = true)]
+#[command(styles = help_styles())]
pub struct Cli {
/// Change working directory
#[arg(short = 'C', global = true, value_name = "path")]
@@ -291,7 +329,7 @@ Docs: https://llm.datasette.io/ | https://github.com/sigoden/aichat
},
/// List worktrees and optionally branches
- #[command(after_help = r#"COLUMNS:
+ #[command(after_help = "COLUMNS:
Branch: Branch name
Status: Quick status symbols (see STATUS SYMBOLS below)
HEAD±: Uncommitted changes vs HEAD (+added -deleted lines, staged + unstaged)
@@ -300,11 +338,11 @@ Docs: https://llm.datasette.io/ | https://github.com/sigoden/aichat
Path: Worktree directory location
Remote⇅: Commits ahead↑/behind↓ relative to tracking branch (e.g. origin/branch)
CI (--full): CI pipeline status (tries PR/MR checks first, falls back to branch workflows)
- ● passed (green) - All checks passed
- ● running (blue) - Checks in progress
- ● failed (red) - Checks failed
- ● conflicts (yellow) - Merge conflicts with base
- ● no-ci (gray) - PR/MR or workflow found but no checks configured
+ \x1b[32m●\x1b[0m passed (green) - All checks passed
+ \x1b[34m●\x1b[0m running (blue) - Checks in progress
+ \x1b[31m●\x1b[0m failed (red) - Checks failed
+ \x1b[33m●\x1b[0m conflicts (yellow) - Merge conflicts with base
+ \x1b[90m●\x1b[0m no-ci (gray) - PR/MR or workflow found but no checks configured
(blank) - No PR/MR or workflow found, or gh/glab CLI unavailable
(dimmed) - Stale: unpushed local changes differ from PR/MR head
Commit: Short commit hash (8 chars)
@@ -313,7 +351,7 @@ Docs: https://llm.datasette.io/ | https://github.com/sigoden/aichat
STATUS SYMBOLS (order: = ≡∅ ↻⋈ ◇⊠⚠ ↑↓ ⇡⇣ ?!+»✘):
· Branch without worktree (no working directory to check)
- = Merge conflicts (unmerged paths in working tree)
+ \x1b[31m=\x1b[0m Merge conflicts (unmerged paths OR --full detected conflicts with main)
≡ Working tree matches main (identical contents, regardless of commit history)
∅ No commits (no commits ahead AND no uncommitted changes)
↻ Rebase in progress
@@ -331,7 +369,7 @@ STATUS SYMBOLS (order: = ≡∅ ↻⋈ ◇⊠⚠ ↑↓ ⇡⇣ ?!+»✘):
» Renamed files
✘ Deleted files
-Rows are dimmed when no unique work (≡ matches main OR ∅ no commits)."#)]
+Rows are dimmed when no unique work (≡ matches main OR ∅ no commits).")]
List {
/// Output format
#[arg(long, value_enum, default_value = "table")]
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index 7f54e3815..ba987a008 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -59,10 +59,10 @@ fn test_init_invalid_shell() {
----- stdout -----
----- stderr -----
- error: invalid value 'invalid-shell' for '<SHELL>'
- [possible values: bash, fish, zsh]
+ error: invalid value 'invalid-shell' for '<SHELL>'
+ [possible values: bash, fish, zsh]
- For more information, try '--help'.
+ For more information, try '--help'.
");
});
}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap
index b6e4eda0d..aa97f8788 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap
@@ -2,8 +2,8 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-error: unrecognized subcommand 'foo'
+error: unrecognized subcommand 'foo'
-Usage: wt [OPTIONS] <COMMAND>
+Usage: wt [OPTIONS] <COMMAND>
-For more information, try '--help'.
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
index 13412ebb0..4c24beecc 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
@@ -17,17 +17,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmprsklIC/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpD1BMpv/test-config.toml
---
success: false
exit_code: 2
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
+error: unexpected argument '--no-hooks' found
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
+ tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-Usage: wt merge <TARGET>
+Usage: wt merge <TARGET>
-For more information, try '--help'.
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
index a1ccda965..bf57d199d 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
@@ -20,17 +20,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpunJx6g/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpI4D74J/test-config.toml
---
success: false
exit_code: 2
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
+error: unexpected argument '--no-hooks' found
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
+ tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-Usage: wt switch --create --execute <EXECUTE> <BRANCH>
+Usage: wt switch --create --execute <EXECUTE> <BRANCH>
-For more information, try '--help'.
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
index c7dc69d67..81cf9c395 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
@@ -19,17 +19,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpPjPbkB/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVoCJU2/test-config.toml
---
success: false
exit_code: 2
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
+error: unexpected argument '--no-hooks' found
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
+ tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-Usage: wt switch --execute <EXECUTE> <BRANCH>
+Usage: wt switch --execute <EXECUTE> <BRANCH>
-For more information, try '--help'.
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
index 7e7e96c74..710010c24 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
@@ -15,21 +15,21 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYcrfhx
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp8YFTXv
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpmcitcx/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5CN1y0/test-config.toml
---
success: false
exit_code: 2
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
+error: unexpected argument '--no-hooks' found
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
+ tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-Usage: wt switch --create <BRANCH>
+Usage: wt switch --create <BRANCH>
-For more information, try '--help'.
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
index 9e654dca9..eee0c559e 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
@@ -16,21 +16,21 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpl7vTtp
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpaTfxoG
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpFDPJ2x/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpaxOPAA/test-config.toml
---
success: false
exit_code: 2
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
+error: unexpected argument '--no-hooks' found
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
+ tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-Usage: wt switch --create --force <BRANCH>
+Usage: wt switch --create --force <BRANCH>
-For more information, try '--help'.
+For more information, try '--help'.