Skip to main content

submodule_kit/
lib.rs

1pub mod commands;
2pub mod strings;
3pub mod submodule;
4
5use clap::{Parser, Subcommand};
6use commands::is::IsCondition;
7
8#[derive(Parser)]
9#[command(
10    name = "submodule-kit",
11    about = "A CLI toolkit for managing git submodules"
12)]
13struct Cli {
14    #[command(subcommand)]
15    command: Commands,
16}
17
18#[derive(Subcommand)]
19enum Commands {
20    /// List all submodules
21    List,
22    /// Check one or more conditions about submodules; exits 0 (all true) or 1 (any false)
23    Is { conditions: Vec<IsCondition> },
24    #[command(hide = true)]
25    GenerateDocs,
26}
27
28pub fn run() {
29    let cli = Cli::parse();
30
31    match cli.command {
32        Commands::List => {
33            if let Err(e) = commands::list::run() {
34                eprintln!("error: {e}");
35                std::process::exit(2);
36            }
37        }
38        Commands::Is { conditions } => match commands::is::run(conditions) {
39            Ok(true) => {}
40            Ok(false) => std::process::exit(1),
41            Err(e) => {
42                eprintln!("error: {e}");
43                std::process::exit(2);
44            }
45        },
46        Commands::GenerateDocs => {
47            print!(
48                "{}\n## License\n\nMIT — see [LICENSE](LICENSE)\n",
49                clap_markdown::help_markdown::<Cli>()
50            );
51        }
52    }
53}