spec_driven_docs/cli.rs
1//! Root clap parser.
2//!
3//! Holds the top-level [`Cli`], the [`Commands`] enum, and the global args.
4//! Per-subcommand arg structs live in sibling files (`cli/<name>.rs`). No
5//! business logic anywhere in this module tree.
6
7pub mod completions;
8pub mod gate;
9pub mod hooks;
10pub mod init;
11pub mod license;
12pub mod read;
13pub mod skill;
14pub mod status;
15pub mod upgrade;
16pub mod verify;
17
18use clap::{ArgAction, Parser, Subcommand};
19
20/// The `sdd` command line.
21#[derive(Debug, Parser)]
22#[command(name = "sdd", version, about, long_about = None)]
23pub struct Cli {
24 /// Flags every subcommand shares.
25 #[command(flatten)]
26 pub global: GlobalArgs,
27
28 /// The subcommand to run.
29 #[command(subcommand)]
30 pub command: Commands,
31}
32
33/// Flags every subcommand shares.
34#[derive(Debug, clap::Args)]
35pub struct GlobalArgs {
36 /// Increase log verbosity (-v info, -vv debug, -vvv trace).
37 /// Overridden by `RUST_LOG` if set.
38 #[arg(short, long, action = ArgAction::Count, global = true)]
39 pub verbose: u8,
40}
41
42/// Every subcommand `sdd` offers.
43#[derive(Debug, Subcommand)]
44pub enum Commands {
45 /// Install the payload into a target repository.
46 Init(init::InitArgs),
47 /// Verify an installed instance offline.
48 Verify(verify::VerifyArgs),
49 /// Upgrade an installed instance to this binary's version.
50 Upgrade(upgrade::UpgradeArgs),
51 /// Run one delivered gate, or list them all.
52 Gate(gate::GateArgs),
53 /// Render the delivered gate set as pre-commit hook entries.
54 Hooks(hooks::HooksArgs),
55 /// Read a method chapter, or list them.
56 Method(read::ReadArgs),
57 /// Read a spec seed, or list them.
58 Spec(read::ReadArgs),
59 /// Read a document template, or list them.
60 Template(read::ReadArgs),
61 /// Read the embedded skills, or install them for coding agents.
62 Skill(skill::SkillArgs),
63 /// Report an instance's state without gating on it.
64 Status(status::StatusArgs),
65 /// Print the license terms this binary carries.
66 License(license::LicenseArgs),
67 /// Regenerate the canon checkout's own instance manifest.
68 SelfManifest,
69 /// Generate shell completions.
70 Completions(completions::CompletionsArgs),
71 /// Render the manual page.
72 Man,
73}
74
75/// Every subcommand name the binary answers to.
76#[must_use]
77pub fn subcommand_names() -> Vec<String> {
78 <Cli as clap::CommandFactory>::command()
79 .get_subcommands()
80 .map(|command| command.get_name().to_string())
81 .collect()
82}