1mod check;
11mod cli;
12mod clippy;
13#[doc(hidden)]
14pub mod codes;
15mod diff;
16mod dotenv;
17mod explain;
18mod files;
19mod git;
20mod init;
21mod mode;
22mod run;
23mod scan;
24mod spec;
25
26use std::ffi::OsString;
27use std::process::ExitCode;
28
29use clap::CommandFactory as _;
30
31#[doc(hidden)]
32pub use crate::cli::{Cli, TOOL};
33use crate::cli::{CommandsCommand, CompletionCommand, SKILL, SchemasCommand, SelfCommand, Verb};
34
35#[doc(hidden)]
44#[must_use = "the exit code reports how the command ended, so return it from main"]
45pub fn run<I, T>(args: I, vars: Vec<(OsString, OsString)>) -> ExitCode
46where
47 I: IntoIterator<Item = T>,
48 T: Into<OsString> + Clone,
49{
50 let (cli, mut output) = match crumbkit::parse_from::<Cli>(&TOOL, args) {
51 Ok(parsed) => parsed,
52 Err(stop) => return stop.exit_code(),
53 };
54 match cli.verb {
55 Verb::Init(args) => {
56 let dry_run = output.is_dry_run();
57 let listing = if args.clippy {
58 init::ban(&args, dry_run)
59 } else {
60 init::init(&args, dry_run)
61 };
62 crumbkit::finish(output, init::INIT, listing)
63 }
64 Verb::Check(args) => crumbkit::finish(output, check::CHECK, check::check(&args, vars)),
65 Verb::Explain(args) => {
66 crumbkit::finish(output, explain::EXPLAIN, explain::explain(&args, vars))
67 }
68 Verb::Diff(args) => crumbkit::finish(output, diff::DIFF, diff::diff(&args)),
69 Verb::Run(args) => {
70 #[expect(
71 clippy::disallowed_methods,
72 reason = "run prints its notes on standard error before the child takes the terminal, after which nothing of starmap prints"
73 )]
74 let mut notes = std::io::stderr();
75 run::run(&args, vars, output, &mut notes)
76 }
77 Verb::Commands {
80 command: CommandsCommand::List(args),
81 } => {
82 let result = crumbkit::commands::list(&mut output, &TOOL, &args);
83 crumbkit::finish(output, crumbkit::commands::COMMANDS_LIST, result)
84 }
85 Verb::Schemas {
86 command: SchemasCommand::List(args),
87 } => {
88 let result = crumbkit::schemas::list(&mut output, &TOOL, &args);
89 crumbkit::finish(output, crumbkit::schemas::SCHEMAS_LIST, result)
90 }
91 Verb::Schemas {
92 command: SchemasCommand::Show(args),
93 } => {
94 let result = crumbkit::schemas::show(&mut output, &TOOL, &args);
95 crumbkit::finish(output, crumbkit::schemas::SCHEMAS_SHOW, result)
96 }
97 Verb::SelfCommand {
98 command: SelfCommand::Usage(args),
99 } => {
100 let result =
101 Ok::<_, crumbkit::Error>(crumbkit_usage::findings(&mut output, &TOOL, &args));
102 crumbkit::finish(output, crumbkit_usage::SELF_USAGE, result)
103 }
104 Verb::Skills { command } => crumbkit_skills::run(output, &[SKILL], command),
105 Verb::Completion { command } => match command {
106 CompletionCommand::Install(args) => {
107 let result = crumbkit::completion::install(Cli::command, &args);
108 crumbkit::finish(output, crumbkit::completion::COMPLETION_INSTALL, result)
109 }
110 CompletionCommand::Check(args) => {
111 let result = crumbkit::completion::check(Cli::command, &args);
112 crumbkit::finish(output, crumbkit::completion::COMPLETION_CHECK, result)
113 }
114 CompletionCommand::Print(args) => {
115 let result = crumbkit::completion::print(Cli::command, &args);
116 crumbkit::finish(output, crumbkit::completion::COMPLETION_PRINT, result)
117 }
118 },
119 }
120}