use crate::AppModel;
use crate::actions::ActionsState;
use crate::cli_outbound::Cli;
use crate::names::SplitMix64;
use crate::start::{self, Deps, StartInputs};
use std::path::Path;
pub(super) fn fire_start(
model: &mut AppModel,
actions: &mut ActionsState,
lernie: &Cli,
bl: &Cli,
mint_seed: u64,
text: &str,
) -> bool {
let dir = actions.path_dir.trim().to_owned();
let inputs = if dir.is_empty() {
model.start_bare_inputs()
} else {
model.start_path_inputs(Path::new(&dir))
};
fire_inputs(model, actions, lernie, bl, inputs, mint_seed, text)
}
pub(super) fn fire_bare(
model: &mut AppModel,
actions: &mut ActionsState,
lernie: &Cli,
bl: &Cli,
mint_seed: u64,
text: &str,
) -> bool {
let inputs = model.start_bare_inputs();
fire_inputs(model, actions, lernie, bl, inputs, mint_seed, text)
}
fn fire_inputs(
model: &mut AppModel,
actions: &mut ActionsState,
lernie: &Cli,
bl: &Cli,
inputs: StartInputs,
mint_seed: u64,
text: &str,
) -> bool {
let mut rng = SplitMix64::from_seed(mint_seed);
let deps = Deps {
bl: bl.clone(),
lernie: lernie.clone(),
state_root: model.state_root().to_path_buf(),
gate: model.toolchain().clone(),
};
let launched = match start::prepare(&deps, &inputs, &mut rng, &super::now_ts()) {
Ok(p) => start::execute_prompt(
lernie,
model.state_root(),
&super::now_ts(),
&p.name,
&p.cwd,
&p.workspace,
text,
)
.is_ok(),
Err(_) => false,
};
model.after_lernie_verb();
actions.last_failure = model.last_failure();
launched
}