use super::{Error, Fx, Outcome};
use crate::harness_root;
use crate::prompt::inbox::AdvanceLauncher;
use crate::prompt::{self, NanoIdGen, SpawnAdapter, SpawnTool, SystemClock};
use crate::template::RealGit;
use crate::workspace;
use std::path::PathBuf;
#[derive(clap::Args, Debug)]
pub struct Args {
pub repo: PathBuf,
pub message: String,
#[arg(long)]
pub from: Option<String>,
#[arg(long)]
pub config: Option<String>,
#[arg(long)]
pub name: Option<String>,
#[arg(long = "pin", value_name = "DEST=SRC")]
pub pin: Vec<String>,
#[arg(long, value_name = "PATH")]
pub cwd: Option<PathBuf>,
}
pub fn run(args: Args, fx: &mut Fx) -> Result<Outcome, Error> {
go(args, fx)
.map(Outcome::Line)
.map_err(|e| Error::new("prompt", e))
}
fn go(args: Args, fx: &mut Fx) -> Result<String, Box<dyn std::error::Error>> {
let pins = prompt::pinned_doc::load(&args.pin)?;
let cwd = args
.cwd
.as_deref()
.map(workspace::cwd::resolve)
.transpose()?;
let roots = harness_root::resolve()?;
let tool_executor = SpawnTool::new(&roots.data, &SystemClock, &fx.driver_target)
.with_injection(fx.tool_injection);
let launcher = AdvanceLauncher::with_exe(fx.driver_target.clone());
let deps = prompt::Deps {
adapter: &SpawnAdapter,
sleeper: &prompt::RealSleeper,
git: &RealGit::new(),
clock: &SystemClock,
id_gen: &NanoIdGen,
tool_executor: &tool_executor,
config_root: &roots.config,
adapter_target: fx.adapter_target.as_deref(),
stop: fx.stop,
launcher: &launcher,
rng: &crate::mint::SplitMix64::from_entropy(),
};
prompt::run(
&args.repo,
&args.message,
args.from.as_deref(),
args.config.as_deref(),
args.name.as_deref(),
&pins,
cwd.as_deref(),
&deps,
)
.map_err(Into::into)
}