1mod cli;
2mod commands;
3mod discovery;
4mod error;
5mod model;
6mod output;
7mod preferences;
8mod registry;
9
10pub use error::{Result, RunbookError};
11
12use cli::{CommandArgs, parse_args};
13use commands::category::{CategoryCommand, query_category};
14use commands::prefer::{PreferCommand, run_prefer};
15use commands::scan::{ScanCommand, scan};
16use model::{CategoryInput, PreferAction, PreferInput, ScanInput, ToolPreference};
17
18pub fn run() -> Result<()> {
19 match parse_args(std::env::args().skip(1)) {
20 CommandArgs::Help => {
21 println!("{}", cli::help_text());
22 Ok(())
23 }
24 CommandArgs::CategoryHelp => {
25 println!("{}", cli::category_help_text());
26 Ok(())
27 }
28 CommandArgs::PreferHelp => {
29 println!("{}", cli::prefer_help_text());
30 Ok(())
31 }
32 CommandArgs::Version => {
33 println!("runbook {}", env!("CARGO_PKG_VERSION"));
34 Ok(())
35 }
36 CommandArgs::Invalid(reason) => Err(RunbookError::usage(reason, cli::help_text())),
37 CommandArgs::Scan { mode, minimal } => {
38 let cwd = std::env::current_dir().map_err(RunbookError::current_dir)?;
39 let result = scan(ScanCommand {
40 input: ScanInput { cwd, mode, minimal },
41 });
42 println!("{}", output::render_scan(&result));
43 Ok(())
44 }
45 CommandArgs::Category { categories, lang } => {
46 let cwd = std::env::current_dir().map_err(RunbookError::current_dir)?;
47 let result = query_category(CategoryCommand {
48 input: CategoryInput {
49 cwd,
50 categories,
51 lang,
52 },
53 })?;
54 println!("{}", output::render_category(&result));
55 Ok(())
56 }
57 CommandArgs::Prefer { action } => {
58 let cwd = std::env::current_dir().map_err(RunbookError::current_dir)?;
59 let action = match action {
60 cli::PreferArgs::List => PreferAction::List,
61 cli::PreferArgs::Set {
62 category,
63 lang,
64 tool,
65 reason,
66 } => PreferAction::Set(ToolPreference {
67 category,
68 lang,
69 tool,
70 reason,
71 }),
72 cli::PreferArgs::Unset { category, lang } => PreferAction::Unset { category, lang },
73 };
74 let result = run_prefer(PreferCommand {
75 input: PreferInput { cwd, action },
76 })?;
77 println!("{}", output::render_prefer(&result));
78 Ok(())
79 }
80 }
81}