ralph_workflow/cli/init/config_generation/
global.rs1use crate::config::{ConfigEnvironment, RealConfigEnvironment};
7use crate::logger::Colors;
8
9pub fn handle_init_global_with<R: ConfigEnvironment>(
24 colors: Colors,
25 env: &R,
26) -> anyhow::Result<bool> {
27 let global_path = env
28 .unified_config_path()
29 .ok_or_else(|| anyhow::anyhow!("Cannot determine config directory (no home directory)"))?;
30
31 if env.file_exists(&global_path) {
33 println!(
34 "{}Unified config already exists:{} {}",
35 colors.yellow(),
36 colors.reset(),
37 global_path.display()
38 );
39 println!("Edit the file to customize, or delete it to regenerate from defaults.");
40 println!();
41 println!("Next steps:");
42 println!(" 1. Create a PROMPT.md for your task:");
43 println!(" ralph --init <work-guide>");
44 println!(" ralph --list-work-guides # Show all Work Guides");
45 println!(" 2. Or run ralph directly with default settings:");
46 println!(" ralph \"your commit message\"");
47 return Ok(true);
48 }
49
50 env.write_file(&global_path, crate::config::unified::DEFAULT_UNIFIED_CONFIG)
52 .map_err(|e| {
53 anyhow::anyhow!(
54 "Failed to create config file {}: {}",
55 global_path.display(),
56 e
57 )
58 })?;
59
60 println!(
61 "{}Created unified config: {}{}{}\n",
62 colors.green(),
63 colors.bold(),
64 global_path.display(),
65 colors.reset()
66 );
67 println!("This is the primary configuration file for Ralph.");
68 println!();
69 println!("Features:");
70 println!(" - General settings (verbosity, iterations, etc.)");
71 println!(" - CCS aliases for Claude Code Switch integration");
72 println!(" - Custom agent definitions");
73 println!(" - Agent chain configuration with fallbacks");
74 println!();
75 println!("Environment variables (RALPH_*) override these settings.");
76 println!();
77 println!("Next steps:");
78 println!(" 1. Create a PROMPT.md for your task:");
79 println!(" ralph --init <work-guide>");
80 println!(" ralph --list-work-guides # Show all Work Guides");
81 println!(" 2. Or run ralph directly with default settings:");
82 println!(" ralph \"your commit message\"");
83 Ok(true)
84}
85
86pub fn handle_init_global(colors: Colors) -> anyhow::Result<bool> {
100 handle_init_global_with(colors, &RealConfigEnvironment)
101}
102
103pub fn handle_init_none_exist_with_env<R: ConfigEnvironment>(
107 _config_path: &std::path::Path,
108 colors: Colors,
109 env: &R,
110) -> anyhow::Result<bool> {
111 println!(
112 "{}No config found. Creating unified config...{}",
113 colors.dim(),
114 colors.reset()
115 );
116 println!();
117 handle_init_global_with(colors, env)?;
118 Ok(true)
119}