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::{
34 CommandsCommand, CompletionCommand, SKILL, SchemasCommand, SelfCommand, SkillsCommand, Verb,
35};
36
37#[doc(hidden)]
46#[must_use]
47pub fn run<I, T>(args: I, vars: Vec<(OsString, OsString)>) -> ExitCode
48where
49 I: IntoIterator<Item = T>,
50 T: Into<OsString> + Clone,
51{
52 let (cli, mut output) = match crumbkit::parse_from::<Cli>(&TOOL, args) {
53 Ok(parsed) => parsed,
54 Err(stop) => return stop.exit_code(),
55 };
56 match cli.verb {
57 Verb::Init(args) => {
58 let dry_run = output.is_dry_run();
59 let listing = if args.clippy {
60 init::ban(&args, dry_run)
61 } else {
62 init::init(&args, dry_run)
63 };
64 crumbkit::finish(output, init::INIT, listing)
65 }
66 Verb::Check(args) => crumbkit::finish(output, check::CHECK, check::check(&args, vars)),
67 Verb::Explain(args) => {
68 crumbkit::finish(output, explain::EXPLAIN, explain::explain(&args, vars))
69 }
70 Verb::Diff(args) => crumbkit::finish(output, diff::DIFF, diff::diff(&args)),
71 Verb::Run(args) => {
72 #[expect(
73 clippy::disallowed_methods,
74 reason = "run prints its notes on standard error before the child takes the terminal, after which nothing of starmap prints"
75 )]
76 let mut notes = std::io::stderr();
77 run::run(&args, vars, output, &mut notes)
78 }
79 Verb::Commands {
82 command: CommandsCommand::List(args),
83 } => {
84 let result = crumbkit::commands::list(&mut output, &TOOL, &args);
85 crumbkit::finish(output, crumbkit::commands::COMMANDS_LIST, result)
86 }
87 Verb::Schemas {
88 command: SchemasCommand::List(args),
89 } => {
90 let result = crumbkit::schemas::list(&mut output, &TOOL, &args);
91 crumbkit::finish(output, crumbkit::schemas::SCHEMAS_LIST, result)
92 }
93 Verb::Schemas {
94 command: SchemasCommand::Show(args),
95 } => {
96 let result = crumbkit::schemas::show(&mut output, &TOOL, &args);
97 crumbkit::finish(output, crumbkit::schemas::SCHEMAS_SHOW, result)
98 }
99 Verb::SelfCommand {
100 command: SelfCommand::Usage(args),
101 } => {
102 let result =
103 Ok::<_, crumbkit::Error>(crumbkit_usage::findings(&mut output, &TOOL, &args));
104 crumbkit::finish(output, crumbkit_usage::SELF_USAGE, result)
105 }
106 Verb::Skills { command } => match command {
107 SkillsCommand::Install(args) => {
108 let result = Ok::<_, crumbkit::Error>(crumbkit_skills::install(&SKILL, &args));
109 crumbkit::finish(output, crumbkit_skills::SKILLS_INSTALL, result)
110 }
111 SkillsCommand::Check(args) => {
112 let result = Ok::<_, crumbkit::Error>(crumbkit_skills::check(&SKILL, &args));
113 crumbkit::finish(output, crumbkit_skills::SKILLS_CHECK, result)
114 }
115 SkillsCommand::Print => {
116 let result = Ok::<_, crumbkit::Error>(crumbkit_skills::print(&SKILL));
117 crumbkit::finish(output, crumbkit_skills::SKILLS_PRINT, result)
118 }
119 },
120 Verb::Completion { command } => match command {
121 CompletionCommand::Install(args) => {
122 let result = crumbkit::completion::install(Cli::command, &args);
123 crumbkit::finish(output, crumbkit::completion::COMPLETION_INSTALL, result)
124 }
125 CompletionCommand::Check(args) => {
126 let result = crumbkit::completion::check(Cli::command, &args);
127 crumbkit::finish(output, crumbkit::completion::COMPLETION_CHECK, result)
128 }
129 CompletionCommand::Print(args) => {
130 let result = crumbkit::completion::print(Cli::command, &args);
131 crumbkit::finish(output, crumbkit::completion::COMPLETION_PRINT, result)
132 }
133 },
134 }
135}