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::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 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(
38        &InitOptions {
39            target: args.target,
40            profile: args.profile,
41            apply: args.apply,
42            dry_run: args.dry_run,
43            docs_scratch,
44            reserve: args.reserve,
45            writing_style,
46        },
47        &crate::release::embedded::EmbeddedReleaseBundle::new(),
48        Intent::Init,
49    )?;
50    for line in &outcome.lines {
51        output::line(line);
52    }
53    Ok(())
54}