1pub mod cli;
2pub mod client;
3pub mod browse;
4pub mod daemon;
5pub mod format;
6
7use clap::CommandFactory;
8use clap::Parser;
9use clap_complete::generate;
10use cli::Cli;
11
12pub fn run() -> Result<(), Box<dyn std::error::Error>> {
13 let cli = Cli::parse();
14 if let Some(shell) = cli.completions {
15 let mut cmd = Cli::command();
16 let name = cmd.get_name().to_string();
17 generate(shell, &mut cmd, name, &mut std::io::stdout());
18 return Ok(());
19 }
20 let cmd = match cli.command {
21 Some(c) => c,
22 None => {
23 let _ = Cli::command().print_help();
24 std::process::exit(1);
25 }
26 };
27 match cmd {
28 cli::Command::Browse(args) => browse::run(args),
29 cli::Command::Daemon(args) => daemon::run(args),
30 cli::Command::Health(args) => client::health(args.port, args.json),
31 cli::Command::Format(args) => format::run(args),
32 }
33}