Skip to main content

spec_driven_docs/commands/
init.rs

1//! `init` subcommand: runtime-shape.
2//!
3//! Projects the flags into the installer's options and prints its report.
4//! Install semantics live in `services::installer`.
5
6use crate::cli::init::InitArgs;
7use crate::context::AppContext;
8use crate::domain::manifest::{PlanZone, parse_docs_scratch};
9use crate::error::AppError;
10use crate::output;
11use crate::services::installer::{InitOptions, init};
12
13/// Install the payload into a target repository.
14///
15/// # Errors
16///
17/// Whatever the installer refuses; see [`init`].
18pub fn run(_ctx: &AppContext, args: InitArgs) -> Result<(), AppError> {
19    let plan_zone = args
20        .plan_zone
21        .as_deref()
22        .map(PlanZone::parse)
23        .transpose()
24        .map_err(|error| AppError::Usage(format!("--plan-zone: {error}")))?;
25    let docs_scratch = args
26        .docs_scratch
27        .as_deref()
28        .map(parse_docs_scratch)
29        .transpose()
30        .map_err(|error| AppError::Usage(format!("--docs-scratch: {error}")))?;
31    let writing_style = args
32        .writing_style
33        .as_deref()
34        .map(crate::domain::instance_config::WritingStyle::parse_flag)
35        .transpose()
36        .map_err(|error| AppError::Usage(format!("--writing-style: {error}")))?;
37    let outcome = init(&InitOptions {
38        target: args.target,
39        profile: args.profile,
40        apply: args.apply,
41        dry_run: args.dry_run,
42        plan_zone,
43        docs_scratch,
44        reserve: args.reserve,
45        writing_style,
46    })?;
47    for line in &outcome.lines {
48        output::line(line);
49    }
50    Ok(())
51}