use super::{Error, Fx, Outcome};
use crate::harness_root;
use crate::template::authoring::Pass;
use crate::template::{self, RealGit};
use std::path::PathBuf;
#[derive(clap::Args, Debug)]
pub struct Args {
pub workspace: PathBuf,
pub name: Option<String>,
#[arg(long)]
pub from: Option<String>,
#[arg(long)]
pub orphan: bool,
}
pub fn run(args: Args, fx: &mut Fx) -> Result<Outcome, Error> {
go(args, fx).map_err(|e| Error::new("config", e))
}
fn go(args: Args, fx: &mut Fx) -> Result<Outcome, Box<dyn std::error::Error>> {
let roots = harness_root::resolve()?;
let pass = template::authoring::from_cli(
&args.workspace,
&roots.data,
args.name.as_deref(),
args.from.as_deref(),
args.orphan,
fx.editor,
&RealGit::new(),
)?;
Ok(match pass {
Pass::Landed => Outcome::Quiet,
Pass::Declined { target } => Outcome::Line(format!(
"{target} unchanged: the edit changed nothing, so no config commit was authored"
)),
})
}