ralph_workflow/cli/init/
smart_init.rs1pub fn handle_smart_init_with<R: ConfigEnvironment>(
21 template_arg: Option<&str>,
22 force: bool,
23 colors: Colors,
24 env: &R,
25) -> anyhow::Result<bool> {
26 let config_path = env
27 .unified_config_path()
28 .ok_or_else(|| anyhow::anyhow!("Cannot determine config directory (no home directory)"))?;
29 let prompt_path = env.prompt_path();
30 handle_smart_init_at_paths_with_env(
31 template_arg,
32 force,
33 colors,
34 &config_path,
35 &prompt_path,
36 env,
37 )
38}
39
40pub fn handle_smart_init(
44 template_arg: Option<&str>,
45 force: bool,
46 colors: Colors,
47) -> anyhow::Result<bool> {
48 handle_smart_init_with(template_arg, force, colors, &RealConfigEnvironment)
49}
50
51fn handle_smart_init_at_paths_with_env<R: ConfigEnvironment>(
52 template_arg: Option<&str>,
53 force: bool,
54 colors: Colors,
55 config_path: &std::path::Path,
56 prompt_path: &Path,
57 env: &R,
58) -> anyhow::Result<bool> {
59 let config_exists = env.file_exists(config_path);
60 let prompt_exists = env.file_exists(prompt_path);
61
62 if let Some(template_name) = template_arg {
64 if !template_name.is_empty() {
65 return handle_init_template_arg_at_path_with_env(
66 template_name,
67 prompt_path,
68 force,
69 colors,
70 env,
71 );
72 }
73 }
75
76 handle_init_state_inference_with_env(
78 config_path,
79 prompt_path,
80 config_exists,
81 prompt_exists,
82 force,
83 colors,
84 env,
85 )
86}
87
88fn handle_init_both_exist(
90 config_path: &std::path::Path,
91 prompt_path: &Path,
92 force: bool,
93 colors: Colors,
94) -> bool {
95 if force {
97 println!(
98 "{}Note:{} --force-overwrite has no effect when not specifying a Work Guide.",
99 colors.yellow(),
100 colors.reset()
101 );
102 println!("Use: ralph --init <work-guide> --force-overwrite to overwrite PROMPT.md");
103 println!();
104 }
105
106 println!("{}Setup complete!{}", colors.green(), colors.reset());
107 println!();
108 println!(
109 " Config: {}{}{}",
110 colors.dim(),
111 config_path.display(),
112 colors.reset()
113 );
114 println!(
115 " PROMPT: {}{}{}",
116 colors.dim(),
117 prompt_path.display(),
118 colors.reset()
119 );
120 println!();
121 println!("You're ready to run Ralph:");
122 println!(" ralph \"your commit message\"");
123 println!();
124 println!("Other commands:");
125 println!(" ralph --list-work-guides # Show all Work Guides");
126 println!(" ralph --init <work-guide> --force-overwrite # Overwrite PROMPT.md");
127 true
128}