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