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 => {
36 tagit_workspace_changelog::bump_changelog(dry_run)?;
37 Ok(())
38 }
39 ChangelogCommand::Init => tagit_workspace_changelog::init_changelog(dry_run),
40 },
41 #[cfg(feature = "release")]
42 Command::Release {
43 dry_run,
44 no_retag,
45 total_order,
46 sign,
47 message,
48 } => tagit_release::release(
49 tagit_package,
50 tagit_version,
51 dry_run,
52 no_retag,
53 total_order,
54 sign,
55 message.as_deref(),
56 ),
57 #[cfg(feature = "diff")]
58 Command::Diff { short } => tagit_diff::diff(short),
59 Command::Completions => {
60 generate(
61 Bash,
62 &mut to_command(),
63 env!("CARGO_PKG_NAME"),
64 &mut std::io::stdout(),
65 );
66 Ok(())
67 }
68 Command::Doc => {
69 std::fs::create_dir_all("target/man1")?;
70 generate_to(to_command(), "target/man1")?;
71 Ok(())
72 }
73 #[cfg(not(feature = "tag"))]
74 Command::Tag { .. } => {
75 let _ = tagit_package;
76 let _ = tagit_version;
77 anyhow::bail!("enable `tag` feature")
78 }
79 #[cfg(not(feature = "sub"))]
80 Command::Sub { .. } => anyhow::bail!("enable `sub` feature"),
81 #[cfg(not(feature = "changelog"))]
82 Command::Changelog { .. } => anyhow::bail!("enable `changelog` feature"),
83 #[cfg(not(feature = "release"))]
84 Command::Release { .. } => anyhow::bail!("enable `release` feature"),
85 #[cfg(not(feature = "diff"))]
86 Command::Diff { .. } => anyhow::bail!("enable `diff` feature"),
87 }
88}