pub mod prompt;
pub mod repo;
use std::path::Path;
use crate::config_init;
use crate::error::Result;
use crate::hf::{self, HfTreeFetcher};
use crate::image_setup;
use crate::init::prompt::{Field, PromptSource};
use crate::paths::global_config_path;
pub async fn run(force: bool, global_override: Option<&Path>) -> Result<()> {
let cwd = std::env::current_dir()?;
let mut prompt = prompt::auto();
let mut hf = hf::auto();
run_with(force, global_override, &cwd, &mut prompt, &mut hf).await
}
pub async fn run_with(
force: bool,
global_override: Option<&Path>,
cwd: &Path,
prompt: &mut impl PromptSource,
hf: &mut impl HfTreeFetcher,
) -> Result<()> {
let global_path = global_config_path(global_override);
if global_path.exists() {
eprintln!(
"[outrig] using existing global config at {}",
global_path.display()
);
} else {
eprintln!(
"[outrig] no global config found at {} -- let's create one.",
global_path.display()
);
config_init::run_with(force, &global_path, prompt, hf).await?;
eprintln!("[outrig] wrote {}", global_path.display());
}
let mut bootstrapped_name = repo::ensure(cwd, &global_path, prompt, hf).await?;
let mut first = true;
loop {
let should_run = if first && bootstrapped_name.is_some() {
true
} else if first {
prompt.ask_bool(&ADD_FIRST_IMAGE_FIELD, true).await?
} else {
prompt.ask_bool(&ADD_ANOTHER_IMAGE_FIELD, false).await?
};
if !should_run {
break;
}
let name = if first {
bootstrapped_name.take()
} else {
None
};
image_setup::add::run_with(cwd, name, force, prompt).await?;
first = false;
}
Ok(())
}
const ADD_FIRST_IMAGE_FIELD: Field = Field {
name: "Add an image-config now?",
description: "Yes: walk through `outrig image add` to scaffold a \
Dockerfile and [images.<name>] block.",
options: &[],
doc_link: "doc/usage/init.md",
};
const ADD_ANOTHER_IMAGE_FIELD: Field = Field {
name: "Add another image-config?",
description: "Yes: scaffold one more image-config via \
`outrig image add`. No: finish init.",
options: &[],
doc_link: "doc/usage/init.md",
};
pub const DOC_SYNC_FIELDS: &[&Field] = &[&ADD_FIRST_IMAGE_FIELD, &ADD_ANOTHER_IMAGE_FIELD];