1use anyhow::Result;
2
3use clap::{Parser, Subcommand};
4
5use crate::{
6 commands::{
7 ChangepackArgs, CheckArgs, ConfigArgs, InitArgs, PublishArgs, UpdateArgs,
8 handle_changepack, handle_check, handle_config, handle_init, handle_publish, handle_update,
9 },
10 options::FilterOptions,
11};
12mod commands;
13mod finders;
14mod options;
15
16#[derive(Parser, Debug)]
17#[command(author, version, about = "changepacks CLI")]
18struct Cli {
19 #[command(subcommand)]
20 command: Option<Commands>,
21
22 #[arg(short, long)]
23 filter: Option<FilterOptions>,
24
25 #[arg(short, long, default_value = "false")]
26 remote: bool,
27}
28#[derive(Subcommand, Debug)]
29enum Commands {
30 Init(InitArgs),
31 Check(CheckArgs),
32 Update(UpdateArgs),
33 Config(ConfigArgs),
34 Publish(PublishArgs),
35}
36
37pub async fn main(args: &[String]) -> Result<()> {
38 let cli = Cli::parse_from(args);
39 if let Some(command) = cli.command {
40 match command {
41 Commands::Init(args) => handle_init(&args).await?,
42 Commands::Check(args) => handle_check(&args).await?,
43 Commands::Update(args) => handle_update(&args).await?,
44 Commands::Config(args) => handle_config(&args).await?,
45 Commands::Publish(args) => handle_publish(&args).await?,
46 }
47 } else {
48 handle_changepack(&ChangepackArgs {
49 filter: cli.filter,
50 remote: cli.remote,
51 })
52 .await?;
53 }
54 Ok(())
55}