Skip to main content

spec_driven_docs/commands/
init.rs

1//! `init` subcommand: runtime-shape.
2//!
3//! A front over the engine. It classifies the target first and serves one
4//! classification: a first landing. A settled corpus or an installed
5//! instance is somebody else's verb, and this one says which rather than
6//! landing seeds beside a convention that is already there.
7//!
8//! Projects the flags into the installer's options and prints its report.
9//! Install semantics live in `services::installer`.
10
11use crate::cli::init::InitArgs;
12use crate::context::AppContext;
13use crate::domain::manifest::{PlanZone, parse_docs_scratch};
14use crate::error::AppError;
15use crate::output;
16use crate::plan::classify::Intent;
17use crate::services::installer::{InitOptions, init};
18
19/// Install the payload into a target repository.
20///
21/// # Errors
22///
23/// Whatever the installer refuses; see [`init`].
24pub fn run(_ctx: &AppContext, args: InitArgs) -> Result<(), AppError> {
25    let plan_zone = args
26        .plan_zone
27        .as_deref()
28        .map(PlanZone::parse)
29        .transpose()
30        .map_err(|error| AppError::Usage(format!("--plan-zone: {error}")))?;
31    let docs_scratch = args
32        .docs_scratch
33        .as_deref()
34        .map(parse_docs_scratch)
35        .transpose()
36        .map_err(|error| AppError::Usage(format!("--docs-scratch: {error}")))?;
37    let writing_style = args
38        .writing_style
39        .as_deref()
40        .map(crate::domain::instance_config::WritingStyle::parse_flag)
41        .transpose()
42        .map_err(|error| AppError::Usage(format!("--writing-style: {error}")))?;
43    let outcome = init(
44        &InitOptions {
45            target: args.target,
46            profile: args.profile,
47            apply: args.apply,
48            dry_run: args.dry_run,
49            plan_zone,
50            docs_scratch,
51            reserve: args.reserve,
52            writing_style,
53        },
54        &crate::release::embedded::EmbeddedReleaseBundle::new(),
55        Intent::Init,
56    )?;
57    for line in &outcome.lines {
58        output::line(line);
59    }
60    Ok(())
61}