mod check;
mod cli;
#[doc(hidden)]
pub mod codes;
mod diff;
mod dotenv;
mod explain;
mod files;
mod git;
mod init;
mod mode;
mod run;
mod scan;
mod spec;
use std::ffi::OsString;
use std::process::ExitCode;
use clap::CommandFactory as _;
#[doc(hidden)]
pub use crate::cli::{Cli, TOOL};
use crate::cli::{
CommandsCommand, CompletionCommand, SKILL, SchemasCommand, SelfCommand, SkillsCommand, Verb,
};
#[doc(hidden)]
#[must_use]
pub fn run<I, T>(args: I, vars: Vec<(OsString, OsString)>) -> ExitCode
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
let (cli, mut output) = match crumbkit::parse_from::<Cli>(&TOOL, args) {
Ok(parsed) => parsed,
Err(stop) => return stop.exit_code(),
};
match cli.verb {
Verb::Init(args) => {
let dry_run = output.is_dry_run();
crumbkit::finish(output, init::INIT, init::init(&args, dry_run))
}
Verb::Check(args) => crumbkit::finish(output, check::CHECK, check::check(&args, vars)),
Verb::Explain(args) => {
crumbkit::finish(output, explain::EXPLAIN, explain::explain(&args, vars))
}
Verb::Diff(args) => crumbkit::finish(output, diff::DIFF, diff::diff(&args)),
Verb::Run(args) => {
#[expect(
clippy::disallowed_methods,
reason = "run prints its notes on standard error before the child takes the terminal, after which nothing of starmap prints"
)]
let mut notes = std::io::stderr();
run::run(&args, vars, output, &mut notes)
}
Verb::Commands {
command: CommandsCommand::List(args),
} => {
let result = crumbkit::commands::list(&mut output, &TOOL, &args);
crumbkit::finish(output, crumbkit::commands::COMMANDS_LIST, result)
}
Verb::Schemas {
command: SchemasCommand::List(args),
} => {
let result = crumbkit::schemas::list(&mut output, &TOOL, &args);
crumbkit::finish(output, crumbkit::schemas::SCHEMAS_LIST, result)
}
Verb::Schemas {
command: SchemasCommand::Show(args),
} => {
let result = crumbkit::schemas::show(&mut output, &TOOL, &args);
crumbkit::finish(output, crumbkit::schemas::SCHEMAS_SHOW, result)
}
Verb::SelfCommand {
command: SelfCommand::Usage(args),
} => {
let result =
Ok::<_, crumbkit::Error>(crumbkit_usage::findings(&mut output, &TOOL, &args));
crumbkit::finish(output, crumbkit_usage::SELF_USAGE, result)
}
Verb::Skills { command } => match command {
SkillsCommand::Install(args) => {
let result = Ok::<_, crumbkit::Error>(crumbkit_skills::install(&SKILL, &args));
crumbkit::finish(output, crumbkit_skills::SKILLS_INSTALL, result)
}
SkillsCommand::Check(args) => {
let result = Ok::<_, crumbkit::Error>(crumbkit_skills::check(&SKILL, &args));
crumbkit::finish(output, crumbkit_skills::SKILLS_CHECK, result)
}
SkillsCommand::Print => {
let result = Ok::<_, crumbkit::Error>(crumbkit_skills::print(&SKILL));
crumbkit::finish(output, crumbkit_skills::SKILLS_PRINT, result)
}
},
Verb::Completion { command } => match command {
CompletionCommand::Install(args) => {
let result = crumbkit::completion::install(Cli::command, &args);
crumbkit::finish(output, crumbkit::completion::COMPLETION_INSTALL, result)
}
CompletionCommand::Check(args) => {
let result = crumbkit::completion::check(Cli::command, &args);
crumbkit::finish(output, crumbkit::completion::COMPLETION_CHECK, result)
}
CompletionCommand::Print(args) => {
let result = crumbkit::completion::print(Cli::command, &args);
crumbkit::finish(output, crumbkit::completion::COMPLETION_PRINT, result)
}
},
}
}