Skip to content

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

feat: Improve consistency of CLI outputs and add config init tests

Maximilian Roos4f7a3b0816dc
diff --git a/CLAUDE.md b/CLAUDE.md
index f4cb01360..14cd273df 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -116,6 +116,13 @@ This provides consistent visual separation and hierarchy:
// ✅ GOOD - standalone message with emoji
println!("{SUCCESS_EMOJI} {GREEN}Created worktree{GREEN:#}");
+// ✅ GOOD - message with path on same line
+let green_bold = GREEN.bold();
+println!(
+ "{SUCCESS_EMOJI} {GREEN}Created config file: {green_bold}{}{green_bold:#}",
+ path.display()
+);
+
// ✅ GOOD - info message for primary status (NOT dimmed - answers user's question)
output::info("All commands already approved")?;
output::info("Commands declined")?;
@@ -141,6 +148,10 @@ println!("{dim}Operation declined{dim:#}");
// ❌ BAD - section header without emoji
println!("Config: {bold}{}{bold:#}", path); // Should have INFO_EMOJI
+// ❌ BAD - path on separate line without emoji
+println!("{SUCCESS_EMOJI} {GREEN}Created config file{GREEN:#}");
+println!("{dim}{}{dim:#}", path.display()); // Should be on same line as success message
+
// ❌ BAD - dimming primary status that answers user's question
output::info(format!("{dim}Commands declined{dim:#}"))?; // Should NOT be dim
```
diff --git a/src/commands/config.rs b/src/commands/config.rs
index acc0d3ca7..140136cd9 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -19,7 +19,7 @@ pub fn handle_config_init() -> Result<(), GitError> {
if config_path.exists() {
let bold = AnstyleStyle::new().bold();
println!(
- "Global config already exists: {bold}{}{bold:#}",
+ "{INFO_EMOJI} Global config already exists: {bold}{}{bold:#}",
config_path.display()
);
println!();
@@ -38,9 +38,11 @@ pub fn handle_config_init() -> Result<(), GitError> {
std::fs::write(&config_path, CONFIG_EXAMPLE).git_context("Failed to write config file")?;
// Success message
- let bold = AnstyleStyle::new().bold();
- println!("{SUCCESS_EMOJI} {GREEN}Created config file{GREEN:#}");
- println!("{bold}{}{bold:#}", config_path.display());
+ let green_bold = GREEN.bold();
+ println!(
+ "{SUCCESS_EMOJI} {GREEN}Created config file: {green_bold}{}{green_bold:#}",
+ config_path.display()
+ );
println!();
println!(
"{HINT_EMOJI} {HINT}Edit this file to customize worktree paths and LLM settings{HINT:#}"
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rs
index 298eecb6c..2aa8a9fb5 100644
--- a/src/commands/repository_ext.rs
+++ b/src/commands/repository_ext.rs
@@ -136,10 +136,7 @@ impl RepositoryCliExt for Repository {
Ok(info) => items.push(ListItem::Branch(info)),
Err(e) => {
println!(
- "{WARNING_EMOJI} {WARNING}Failed to enrich branch {WARNING_BOLD}{branch}{WARNING_BOLD:#}: {e}{WARNING:#}"
- );
- println!(
- "{HINT_EMOJI} {HINT}This branch will be shown with limited information{HINT:#}"
+ "{WARNING_EMOJI} {WARNING}Failed to enrich branch {WARNING_BOLD}{branch}{WARNING_BOLD:#}: {e}{WARNING:#} (will show with limited information)"
);
}
}
diff --git a/tests/integration_tests/config_init.rs b/tests/integration_tests/config_init.rs
new file mode 100644
index 000000000..95a99e561
--- /dev/null
+++ b/tests/integration_tests/config_init.rs
@@ -0,0 +1,83 @@
+use crate::common::{set_temp_home_env, wt_command};
+use insta::Settings;
+use insta_cmd::assert_cmd_snapshot;
+use std::fs;
+use tempfile::TempDir;
+
+/// Test `wt config init` when config already exists (should show info message with emoji)
+#[test]
+fn test_config_init_already_exists() {
+ let temp_home = TempDir::new().unwrap();
+
+ // Create fake global config at XDG path
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ fs::write(
+ global_config_dir.join("config.toml"),
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+"#,
+ )
+ .unwrap();
+
+ let mut settings = Settings::clone_current();
+ settings.set_snapshot_path("../snapshots");
+
+ // Filter out the actual config paths
+ settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
+ settings.add_filter(r"\\", "/");
+
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ cmd.arg("config").arg("init");
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+ ⚪ Global config already exists: [TEMP_HOME]/.config/worktrunk/config.toml
+
+ 💡 Use 'wt config list' to view existing configuration
+
+ ----- stderr -----
+ ");
+ });
+}
+
+/// Test `wt config init` creates new config file
+#[test]
+fn test_config_init_creates_file() {
+ let temp_home = TempDir::new().unwrap();
+
+ // Don't create config file - let init create it
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+
+ let mut settings = Settings::clone_current();
+ settings.set_snapshot_path("../snapshots");
+
+ // Filter out the actual config paths
+ settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
+ settings.add_filter(r"\\", "/");
+
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ cmd.arg("config").arg("init");
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+ ✅ Created config file: [TEMP_HOME]/.config/worktrunk/config.toml
+
+ 💡 Edit this file to customize worktree paths and LLM settings
+
+ ----- stderr -----
+ ");
+ });
+
+ // Verify file was actually created
+ let config_path = global_config_dir.join("config.toml");
+ assert!(config_path.exists(), "Config file should be created");
+}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 1833e4fc9..2382ed95d 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -9,6 +9,7 @@ pub mod bare_repository;
pub mod column_alignment_verification;
pub mod completion;
pub mod completion_validation;
+pub mod config_init;
pub mod config_list;
pub mod configure_shell;
pub mod default_branch;