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