pub fn handle_smart_init_with<R: ConfigEnvironment>(
template_arg: Option<&str>,
force: bool,
colors: Colors,
env: &R,
) -> anyhow::Result<bool> {
let config_path = env
.unified_config_path()
.ok_or_else(|| anyhow::anyhow!("Cannot determine config directory (no home directory)"))?;
let prompt_path = env.prompt_path();
handle_smart_init_at_paths_with_env(
template_arg,
force,
colors,
&config_path,
&prompt_path,
env,
)
}
pub fn handle_smart_init(
template_arg: Option<&str>,
force: bool,
colors: Colors,
) -> anyhow::Result<bool> {
handle_smart_init_with(template_arg, force, colors, &RealConfigEnvironment)
}
fn handle_smart_init_at_paths_with_env<R: ConfigEnvironment>(
template_arg: Option<&str>,
_force: bool,
colors: Colors,
config_path: &std::path::Path,
prompt_path: &Path,
env: &R,
) -> anyhow::Result<bool> {
let _config_exists = env.file_exists(config_path);
let _prompt_exists = env.file_exists(prompt_path);
if let Some(template_name) = template_arg {
if !template_name.is_empty() {
return handle_init_template_arg_at_path_with_env(
template_name,
prompt_path,
colors,
env,
);
}
}
handle_init_state_inference_with_env(
config_path,
prompt_path,
template_arg,
colors,
env,
)
}