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 } => tagit_tag::tag(tagit_package, tagit_version, dry_run, no_retag, total_order),
21 #[cfg(feature = "sub")]
22 Command::Sub { command } => tagit_sub::sub(command.unwrap_or_default()),
23 #[cfg(feature = "changelog")]
24 Command::Changelog { dry_run } => tagit_workspace_changelog::bump_changelog(dry_run),
25 Command::Completions => {
26 generate(
27 Bash,
28 &mut to_command(),
29 env!("CARGO_PKG_NAME"),
30 &mut std::io::stdout(),
31 );
32 Ok(())
33 }
34 Command::Doc => {
35 std::fs::create_dir_all("target/man1")?;
36 generate_to(to_command(), "target/man1")?;
37 Ok(())
38 }
39 #[cfg(not(feature = "tag"))]
40 Command::Tag { .. } => anyhow::bail!("enable `tag` feature"),
41 #[cfg(not(feature = "sub"))]
42 Command::Sub { .. } => anyhow::bail!("enable `sub` feature"),
43 #[cfg(not(feature = "changelog"))]
44 Command::Changelog { .. } => anyhow::bail!("enable `changelog` feature"),
45 }
46}