1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! CLI commands

use clap::{Parser, Subcommand};

pub mod changelog;
pub mod commit;
pub mod config;
pub mod init;
pub mod log;
pub mod release;
mod util;
pub mod version;

#[derive(Debug, Parser)]
#[clap(
    version,
    about = "Misc. tools for conventional commits, versioning, and changelogs"
)]
#[clap(propagate_version = true)]
pub struct Cli {
    #[clap(subcommand)]
    pub commands: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
    /// Inititializes the config
    Init(init::InitArgs),
    /// Shows the current configuration
    Config(config::ConfigArgs),
    /// Creates a conventional commit
    Commit(commit::CommitArgs),
    /// Displays the commit history
    Log(log::LogArgs),
    /// Checks the current version and determines the next version
    Version(version::VersionArgs),
    /// Generates the changelog
    Changelog(changelog::ChangelogArgs),
    /// Creates a release
    Release(release::ReleaseArgs),
}

/// Executes the program
pub fn exec(cli: Cli) -> anyhow::Result<()> {
    match cli.commands {
        Commands::Init(args) => init::run(args),
        Commands::Config(args) => config::run(args),
        Commands::Commit(args) => commit::run(args),
        Commands::Version(args) => version::run(args),
        Commands::Log(args) => log::run(args),
        Commands::Changelog(args) => changelog::run(args),
        Commands::Release(args) => release::run(args),
    }
}