Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Write commented example config to disk
Maximilian Roos0516788184e6
diff --git a/dev/config.example.toml b/dev/config.example.tomlindex 4d78a9233..437337ce3 100644--- a/dev/config.example.toml+++ b/dev/config.example.toml@@ -28,8 +28,8 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"[commit-generation]# Example: Simon Willison's llm CLI (https://github.com/simonw/llm)# Install: pip install llm llm-anthropic-# command = "llm"-# args = ["-m", "claude-haiku-4.5"]+command = "llm"+args = ["-m", "claude-haiku-4.5"]# Alternative: AIChat - Rust-based, supports 20+ providers# Install from: https://github.com/sigoden/aichat@@ -151,26 +151,26 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"# List Command Defaults# Configure default behavior for `wt list`-# [list]-# full = false # Show CI, conflicts, diffs by default-# branches = false # Include branches without worktrees by default-# remotes = false # Include remote branches by default+[list]+full = false # Show CI, conflicts, diffs by default+branches = false # Include branches without worktrees by default+remotes = false # Include remote branches by default# Commit Defaults (shared by `wt beta commit`, `wt beta squash`, and `wt merge`)-# [commit]-# stage = "all" # What to stage: "all", "tracked", or "none"+[commit]+stage = "all" # What to stage: "all", "tracked", or "none"# Merge Command Defaults# Note: `stage` defaults from [commit] section above-# [merge]-# squash = true # Squash commits when merging-# commit = true # Create commit after merge-# remove = true # Remove worktree after merge-# verify = true # Run project hooks+[merge]+squash = true # Squash commits when merging+commit = true # Create commit after merge+remove = true # Remove worktree after merge+verify = true # Run project hooks# Approved Commands# Commands approved for automatic execution after switching worktrees# Auto-populated when you use: wt switch --execute "command" --force-# [[approved-commands]]-# project = "github.com/user/repo"-# command = "npm install"+[[approved-commands]]+project = "github.com/user/repo"+command = "npm install"diff --git a/src/commands/config.rs b/src/commands/config.rsindex b72f10827..674ed1f22 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -8,9 +8,32 @@ use worktrunk::styling::{format_toml, print, println,};-/// Example configuration file content+/// Example configuration file content (displayed in help with values uncommented)const CONFIG_EXAMPLE: &str = include_str!("../../dev/config.example.toml");+/// Comment out all non-comment, non-empty lines for writing to disk+fn comment_out_config(content: &str) -> String {+ let has_trailing_newline = content.ends_with('\n');+ let result = content+ .lines()+ .map(|line| {+ // Comment out non-empty lines that aren't already comments+ if !line.is_empty() && !line.starts_with('#') {+ format!("# {}", line)+ } else {+ line.to_string()+ }+ })+ .collect::<Vec<_>>()+ .join("\n");++ if has_trailing_newline {+ format!("{}\n", result)+ } else {+ result+ }+}+/// Handle the config create commandpub fn handle_config_create() -> anyhow::Result<()> {let config_path = get_global_config_path()@@ -34,8 +57,9 @@ pub fn handle_config_create() -> anyhow::Result<()> {.map_err(|e| anyhow::anyhow!("Failed to create config directory: {}", e))?;}- // Write the example config- std::fs::write(&config_path, CONFIG_EXAMPLE).context("Failed to write config file")?;+ // Write the example config with all values commented out+ let commented_config = comment_out_config(CONFIG_EXAMPLE);+ std::fs::write(&config_path, commented_config).context("Failed to write config file")?;// Success messagelet green_bold = GREEN.bold();diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex ecd14e2f8..33cc61e79 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -64,8 +64,8 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m[commit-generation][0m[2m# Example: Simon Willison's llm CLI (https://github.com/simonw/llm)[0m[2m# Install: pip install llm llm-anthropic[0m- [2m# command = "llm"[0m- [2m# args = ["-m", "claude-haiku-4.5"][0m+ [2mcommand = "llm"[0m+ [2margs = ["-m", "claude-haiku-4.5"][0m[2m[0m[2m# Alternative: AIChat - Rust-based, supports 20+ providers[0m[2m# Install from: https://github.com/sigoden/aichat[0m@@ -187,28 +187,28 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m[0m[2m# List Command Defaults[0m[2m# Configure default behavior for `wt list`[0m- [2m# [list][0m- [2m# full = false # Show CI, conflicts, diffs by default[0m- [2m# branches = false # Include branches without worktrees by default[0m- [2m# remotes = false # Include remote branches by default[0m+ [2m[list][0m+ [2mfull = false # Show CI, conflicts, diffs by default[0m+ [2mbranches = false # Include branches without worktrees by default[0m+ [2mremotes = false # Include remote branches by default[0m[2m[0m[2m# Commit Defaults (shared by `wt beta commit`, `wt beta squash`, and `wt merge`)[0m- [2m# [commit][0m- [2m# stage = "all" # What to stage: "all", "tracked", or "none"[0m+ [2m[commit][0m+ [2mstage = "all" # What to stage: "all", "tracked", or "none"[0m[2m[0m[2m# Merge Command Defaults[0m[2m# Note: `stage` defaults from [commit] section above[0m- [2m# [merge][0m- [2m# squash = true # Squash commits when merging[0m- [2m# commit = true # Create commit after merge[0m- [2m# remove = true # Remove worktree after merge[0m- [2m# verify = true # Run project hooks[0m+ [2m[merge][0m+ [2msquash = true # Squash commits when merging[0m+ [2mcommit = true # Create commit after merge[0m+ [2mremove = true # Remove worktree after merge[0m+ [2mverify = true # Run project hooks[0m[2m[0m[2m# Approved Commands[0m[2m# Commands approved for automatic execution after switching worktrees[0m[2m# Auto-populated when you use: wt switch --execute "command" --force[0m- [2m# [[approved-commands]][0m- [2m# project = "github.com/user/repo"[0m- [2m# command = "npm install"[0m+ [2m[[approved-commands]][0m+ [2mproject = "github.com/user/repo"[0m+ [2mcommand = "npm install"[0m----- stderr -----