1use clap_complete::{generate, shells::Bash};
4use clap_mangen::generate_to;
5#[cfg(feature = "changelog")]
6use tagit_changelog_command::ChangelogCommand;
7use tagit_command::Command;
8
9pub fn run(
11 tagit_package: &'static str,
12 tagit_version: &'static str,
13 command: Command,
14 to_command: impl FnOnce() -> clap::Command,
15) -> anyhow::Result<()> {
16 match command {
17 #[cfg(feature = "tag")]
18 Command::Tag {
19 dry_run,
20 no_retag,
21 total_order,
22 sign,
23 } => tagit_tag::tag(
24 tagit_package,
25 tagit_version,
26 dry_run,
27 no_retag,
28 total_order,
29 sign,
30 ),
31 #[cfg(feature = "sub")]
32 Command::Sub { command } => tagit_sub::sub(command.unwrap_or_default()),
33 #[cfg(feature = "changelog")]
34 Command::Changelog { dry_run, command } => match command.unwrap_or_default() {
35 ChangelogCommand::Bump => tagit_workspace_changelog::bump_changelog(dry_run),
36 ChangelogCommand::Init => tagit_workspace_changelog::init_changelog(dry_run),
37 },
38 #[cfg(feature = "diff")]
39 Command::Diff => tagit_diff::diff(),
40 Command::Completions => {
41 generate(
42 Bash,
43 &mut to_command(),
44 env!("CARGO_PKG_NAME"),
45 &mut std::io::stdout(),
46 );
47 Ok(())
48 }
49 Command::Doc => {
50 std::fs::create_dir_all("target/man1")?;
51 generate_to(to_command(), "target/man1")?;
52 Ok(())
53 }
54 #[cfg(not(feature = "tag"))]
55 Command::Tag { .. } => {
56 let _ = tagit_package;
57 let _ = tagit_version;
58 anyhow::bail!("enable `tag` feature")
59 }
60 #[cfg(not(feature = "sub"))]
61 Command::Sub { .. } => anyhow::bail!("enable `sub` feature"),
62 #[cfg(not(feature = "changelog"))]
63 Command::Changelog { .. } => anyhow::bail!("enable `changelog` feature"),
64 #[cfg(not(feature = "diff"))]
65 Command::Diff => anyhow::bail!("enable `diff` feature"),
66 }
67}