1pub mod prompt;
16pub mod repo;
17
18use std::path::Path;
19
20use crate::config_init;
21use crate::error::Result;
22use crate::hf::{self, HfTreeFetcher};
23use crate::image_setup;
24use crate::init::prompt::{Field, PromptSource};
25use crate::paths::global_config_path;
26
27pub async fn run(force: bool, global_override: Option<&Path>) -> Result<()> {
28 let cwd = std::env::current_dir()?;
29 let mut prompt = prompt::auto();
30 let mut hf = hf::auto();
31 run_with(force, global_override, &cwd, &mut prompt, &mut hf).await
32}
33
34pub async fn run_with(
39 force: bool,
40 global_override: Option<&Path>,
41 cwd: &Path,
42 prompt: &mut impl PromptSource,
43 hf: &mut impl HfTreeFetcher,
44) -> Result<()> {
45 let global_path = global_config_path(global_override);
47 if global_path.exists() {
48 eprintln!(
49 "[outrig] using existing global config at {}",
50 global_path.display()
51 );
52 } else {
53 eprintln!(
54 "[outrig] no global config found at {} -- let's create one.",
55 global_path.display()
56 );
57 config_init::run_with(force, &global_path, prompt, hf).await?;
58 eprintln!("[outrig] wrote {}", global_path.display());
59 }
60
61 let mut bootstrapped_name = repo::ensure(cwd, &global_path, prompt, hf).await?;
65
66 let mut first = true;
73 loop {
74 let should_run = if first && bootstrapped_name.is_some() {
75 true
76 } else if first {
77 prompt.ask_bool(&ADD_FIRST_IMAGE_FIELD, true).await?
78 } else {
79 prompt.ask_bool(&ADD_ANOTHER_IMAGE_FIELD, false).await?
80 };
81 if !should_run {
82 break;
83 }
84 let name = if first {
85 bootstrapped_name.take()
86 } else {
87 None
88 };
89 image_setup::add::run_with(cwd, name, force, prompt).await?;
90 first = false;
91 }
92
93 Ok(())
94}
95
96const ADD_FIRST_IMAGE_FIELD: Field = Field {
97 name: "Add an image-config now?",
98 description: "Yes: walk through `outrig image add` to scaffold a \
99 Dockerfile and [images.<name>] block.",
100 options: &[],
101 doc_link: "doc/usage/init.md",
102};
103
104const ADD_ANOTHER_IMAGE_FIELD: Field = Field {
105 name: "Add another image-config?",
106 description: "Yes: scaffold one more image-config via \
107 `outrig image add`. No: finish init.",
108 options: &[],
109 doc_link: "doc/usage/init.md",
110};
111
112pub const DOC_SYNC_FIELDS: &[&Field] = &[&ADD_FIRST_IMAGE_FIELD, &ADD_ANOTHER_IMAGE_FIELD];