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 outcome = init(&InitOptions {
32        target: args.target,
33        profile: args.profile,
34        apply: args.apply,
35        dry_run: args.dry_run,
36        plan_zone,
37        docs_scratch,
38    })?;
39    for line in &outcome.lines {
40        output::line(line);
41    }
42    Ok(())
43}