1use std::ffi::OsString;
2use std::process::ExitCode;
3
4use super::{CliCommand, parse};
5use crate::commands;
6
7pub fn run<I, T>(arguments: I) -> ExitCode
10where
11 I: IntoIterator<Item = T>,
12 T: Into<OsString> + Clone,
13{
14 let command = match parse(arguments) {
15 Ok(command) => command,
16 Err(error) => {
17 let success = error.exit_code() == 0;
18 if let Err(print_error) = error.print() {
19 eprintln!("error: cannot print command-line diagnostic: {print_error}");
20 }
21 return if success {
22 ExitCode::SUCCESS
23 } else {
24 ExitCode::FAILURE
25 };
26 }
27 };
28 let result = match command {
29 CliCommand::New(options) => commands::new::execute(options),
30 CliCommand::Install => commands::install::execute(),
31 CliCommand::Dev => commands::dev::execute(),
32 CliCommand::Build => commands::build::execute(),
33 CliCommand::Package(options) => commands::package::execute(options),
34 CliCommand::Check(format) => commands::check::execute(format),
35 CliCommand::Doctor {
36 format,
37 checks_only,
38 } => commands::doctor::execute(format, checks_only),
39 CliCommand::Exposure(format) => commands::exposure::execute(format),
40 CliCommand::Routes(format) => commands::routes::execute(format),
41 CliCommand::Modules(format) => commands::modules::execute(format),
42 CliCommand::Services(format) => commands::services::execute(format),
43 CliCommand::Schedule(format) => commands::schedule::execute(format),
44 CliCommand::Run { name, arguments } => commands::run_command::execute(&name, &arguments),
45 CliCommand::Make(options) => commands::make::execute(options),
46 CliCommand::Stubs(cmd) => commands::make::execute_stubs(cmd),
47 CliCommand::Script { name, arguments } => commands::script::execute(&name, &arguments),
48 CliCommand::Db(cmd) => commands::db::execute(cmd),
49 CliCommand::Release(cmd) => commands::release::execute(cmd),
50 CliCommand::Inspect(target) => commands::inspect::execute(target),
51 CliCommand::Mcp(options) => commands::mcp::execute(options),
52 };
53 match result {
54 Ok(()) => ExitCode::SUCCESS,
55 Err(error) => {
56 eprintln!("error: {error}");
57 ExitCode::FAILURE
58 }
59 }
60}