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.yamlindex 6f2c23fbf..50b4ba7e5 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -56,7 +56,7 @@ repos:language: pygreptypes: ["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.rsindex 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 worktrunkconst 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 nameStatus: 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/aichatPath: Worktree directory locationRemote⇅: 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 headCommit: Short commit hash (8 chars)@@ -313,7 +351,7 @@ Docs: https://llm.datasette.io/ | https://github.com/sigoden/aichatSTATUS 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.rsindex 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 ------ [1m[31merror:[0m invalid value '[33minvalid-shell[0m' for '[1m<SHELL>[0m'- [possible values: [32mbash[0m, [32mfish[0m, [32mzsh[0m]+ [1m[31merror:[0m invalid value '[1m[33minvalid-shell[0m' for '[1m[36m<SHELL>[0m'+ [possible values: [1m[32mbash[0m, [1m[32mfish[0m, [1m[32mzsh[0m]- For more information, try '[1m--help[0m'.+ For more information, try '[1m[36m--help[0m'.");});}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.snapindex 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.rsexpression: output.normalized()----[1m[31merror:[0m unrecognized subcommand '[33mfoo[0m'+[1m[31merror:[0m unrecognized subcommand '[1m[33mfoo[0m'-[1m[4mUsage:[0m [1mwt[0m [OPTIONS] <COMMAND>+[1m[32mUsage:[0m [1m[36mwt[0m [36m[OPTIONS][0m [36m<COMMAND>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.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.snapindex 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: CLC_ALL: CSOURCE_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: falseexit_code: 2----- stdout ---------- stderr ------[1m[31merror:[0m unexpected argument '[33m--no-hooks[0m' found+[1m[31merror:[0m unexpected argument '[1m[33m--no-hooks[0m' found- [32mtip:[0m to pass '[33m--no-hooks[0m' as a value, use '[32m-- --no-hooks[0m'+ [1m[32mtip:[0m to pass '[1m[33m--no-hooks[0m' as a value, use '[1m[32m-- --no-hooks[0m'-[1m[4mUsage:[0m [1mwt merge[0m <TARGET>+[1m[32mUsage:[0m [1m[36mwt merge[0m [36m<TARGET>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.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.snapindex 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: CLC_ALL: CSOURCE_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: falseexit_code: 2----- stdout ---------- stderr ------[1m[31merror:[0m unexpected argument '[33m--no-hooks[0m' found+[1m[31merror:[0m unexpected argument '[1m[33m--no-hooks[0m' found- [32mtip:[0m to pass '[33m--no-hooks[0m' as a value, use '[32m-- --no-hooks[0m'+ [1m[32mtip:[0m to pass '[1m[33m--no-hooks[0m' as a value, use '[1m[32m-- --no-hooks[0m'-[1m[4mUsage:[0m [1mwt switch[0m [1m--create[0m [1m--execute[0m <EXECUTE> <BRANCH>+[1m[32mUsage:[0m [1m[36mwt switch[0m [1m[36m--create[0m [1m[36m--execute[0m[36m [0m[36m<EXECUTE>[0m [36m<BRANCH>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.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.snapindex 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: CLC_ALL: CSOURCE_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: falseexit_code: 2----- stdout ---------- stderr ------[1m[31merror:[0m unexpected argument '[33m--no-hooks[0m' found+[1m[31merror:[0m unexpected argument '[1m[33m--no-hooks[0m' found- [32mtip:[0m to pass '[33m--no-hooks[0m' as a value, use '[32m-- --no-hooks[0m'+ [1m[32mtip:[0m to pass '[1m[33m--no-hooks[0m' as a value, use '[1m[32m-- --no-hooks[0m'-[1m[4mUsage:[0m [1mwt switch[0m [1m--execute[0m <EXECUTE> <BRANCH>+[1m[32mUsage:[0m [1m[36mwt switch[0m [1m[36m--execute[0m[36m [0m[36m<EXECUTE>[0m [36m<BRANCH>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYcrfhx+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp8YFTXvLANG: CLC_ALL: CSOURCE_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: falseexit_code: 2----- stdout ---------- stderr ------[1m[31merror:[0m unexpected argument '[33m--no-hooks[0m' found+[1m[31merror:[0m unexpected argument '[1m[33m--no-hooks[0m' found- [32mtip:[0m to pass '[33m--no-hooks[0m' as a value, use '[32m-- --no-hooks[0m'+ [1m[32mtip:[0m to pass '[1m[33m--no-hooks[0m' as a value, use '[1m[32m-- --no-hooks[0m'-[1m[4mUsage:[0m [1mwt switch[0m [1m--create[0m <BRANCH>+[1m[32mUsage:[0m [1m[36mwt switch[0m [1m[36m--create[0m [36m<BRANCH>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.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.snapindex 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/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpl7vTtp+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpaTfxoGLANG: CLC_ALL: CSOURCE_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: falseexit_code: 2----- stdout ---------- stderr ------[1m[31merror:[0m unexpected argument '[33m--no-hooks[0m' found+[1m[31merror:[0m unexpected argument '[1m[33m--no-hooks[0m' found- [32mtip:[0m to pass '[33m--no-hooks[0m' as a value, use '[32m-- --no-hooks[0m'+ [1m[32mtip:[0m to pass '[1m[33m--no-hooks[0m' as a value, use '[1m[32m-- --no-hooks[0m'-[1m[4mUsage:[0m [1mwt switch[0m [1m--create[0m [1m--force[0m <BRANCH>+[1m[32mUsage:[0m [1m[36mwt switch[0m [1m[36m--create[0m [1m[36m--force[0m [36m<BRANCH>[0m-For more information, try '[1m--help[0m'.+For more information, try '[1m[36m--help[0m'.