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