gitcc_cli/
lib.rs

1//! CLI commands
2
3use clap::{Parser, Subcommand};
4
5pub mod changelog;
6pub mod commit;
7pub mod config;
8pub mod init;
9pub mod log;
10pub mod release;
11mod util;
12pub mod version;
13
14#[derive(Debug, Parser)]
15#[clap(
16    version,
17    about = "Misc. tools for conventional commits, versioning, and changelogs"
18)]
19#[clap(propagate_version = true)]
20pub struct Cli {
21    #[clap(subcommand)]
22    pub commands: Commands,
23}
24
25#[derive(Debug, Subcommand)]
26pub enum Commands {
27    /// Inititializes the config
28    Init(init::InitArgs),
29    /// Shows the current configuration
30    Config(config::ConfigArgs),
31    /// Creates a conventional commit
32    Commit(commit::CommitArgs),
33    /// Displays the commit history
34    Log(log::LogArgs),
35    /// Checks the current version and determines the next version
36    Version(version::VersionArgs),
37    /// Generates the changelog
38    Changelog(changelog::ChangelogArgs),
39    /// Creates a release
40    Release(release::ReleaseArgs),
41}
42
43/// Executes the program
44pub fn exec(cli: Cli) -> anyhow::Result<()> {
45    match cli.commands {
46        Commands::Init(args) => init::run(args),
47        Commands::Config(args) => config::run(args),
48        Commands::Commit(args) => commit::run(args),
49        Commands::Version(args) => version::run(args),
50        Commands::Log(args) => log::run(args),
51        Commands::Changelog(args) => changelog::run(args),
52        Commands::Release(args) => release::run(args),
53    }
54}