1use std::path::PathBuf;
8
9use crate::{cli::cmd, core::bootstrap::AppContextArgs};
10use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum};
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
14pub enum FormatArg {
15 Auto,
16 Text,
17 Markdown,
18 Json,
19 Jsonl,
20 Plain,
21}
22
23impl FormatArg {
24 pub fn to_output_format_string(&self, use_json: bool) -> String {
25 match (use_json, self) {
26 (_, FormatArg::Text) => "text".to_string(),
27 (_, FormatArg::Markdown) => "markdown".to_string(),
28 (_, FormatArg::Json) => "json".to_string(),
29 (_, FormatArg::Jsonl) => "jsonl".to_string(),
30 (_, FormatArg::Plain) => "plain".to_string(),
31 (true, FormatArg::Auto) => "json".to_string(),
32 (false, FormatArg::Auto) => "text".to_string(),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Copy, ValueEnum)]
38pub enum ColorMode {
39 Auto,
40 Always,
41 Never,
42}
43
44impl std::fmt::Display for ColorMode {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 match self {
47 ColorMode::Auto => write!(f, "auto"),
48 ColorMode::Always => write!(f, "always"),
49 ColorMode::Never => write!(f, "never"),
50 }
51 }
52}
53
54#[derive(Parser, Debug)]
56#[command(
57 name = "cw",
58 version,
59 author,
60 about = "🧙📜🪄📖✨ Commit Wizard - A Spellbook for Conventional Commits, Semantic Versioning, and Changelog Automation.",
61 propagate_version = true,
62 arg_required_else_help = true
63)]
64pub struct Cli {
65 #[command(flatten)]
67 pub global: GlobalArgs,
68 #[command(subcommand)]
70 pub command: Command,
71}
72
73#[derive(Debug, Clone, Subcommand)]
74pub enum Command {
75 Add(cmd::add::Args),
77 Bump(cmd::bump::Args),
79 Check(cmd::check::Args),
81 Commit(cmd::commit::Args),
83 Config(cmd::config::Args),
85 Doctor(cmd::doctor::Args),
87 Init(cmd::init::Args),
89 Push(cmd::push::Args),
91 Tag(cmd::tag::Args),
93}
94
95#[derive(Debug, Clone, Args)]
96pub struct GlobalArgs {
97 #[arg(short = 'v', long = "verbose", action = ArgAction::Count, global = true)]
99 pub verbose: u8,
100 #[arg(short = 'q', long = "quiet", action = ArgAction::Count, global = true)]
102 pub quiet: u8,
103 #[arg(long, global = true)]
105 pub json: bool,
106 #[arg(long, global = true, default_value_t = FormatArg::Auto, value_enum, conflicts_with = "plain")]
108 pub format: FormatArg,
109 #[arg(long, short = 'p', global = true, conflicts_with = "format")]
111 pub plain: bool,
112 #[arg(long, global = true)]
114 pub dry_run: bool,
115 #[arg(long, value_enum, default_value_t = ColorMode::Auto, global = true)]
117 pub color: ColorMode,
118 #[arg(short = 'C', long = "cwd", global = true, default_value = ".")]
120 pub cwd: PathBuf,
121 #[arg(long, global = true, conflicts_with = "non_interactive")]
123 pub ci: bool,
124 #[arg(long, global = true, conflicts_with = "ci")]
126 pub non_interactive: bool,
127 #[arg(long, short = 'y', global = true)]
129 pub yes: bool,
130 #[arg(long, global = true)]
132 pub force: bool,
133 #[arg(long, global = true)]
135 pub config: Option<PathBuf>,
136 #[arg(long, global = true)]
138 pub registry: Option<String>,
139 #[arg(long = "registry-ref", global = true)]
141 pub registry_ref: Option<String>,
142 #[arg(long = "registry-section", global = true)]
144 pub registry_section: Option<String>,
145}
146
147impl From<GlobalArgs> for AppContextArgs {
148 fn from(args: GlobalArgs) -> Self {
149 Self {
150 verbose: args.verbose,
151 quiet: args.quiet,
152 json: args.json,
153 format: if args.plain {
154 "plain".to_string()
155 } else {
156 args.format.to_output_format_string(args.json)
157 },
158 dry_run: args.dry_run,
159 output_color: args.color.to_string(),
160 cwd: args.cwd,
161 ci: args.ci,
162 non_interactive: args.non_interactive,
163 auto_yes: args.yes,
164 force: args.force,
165 config_path: args.config,
166 registry: args.registry,
167 registry_ref: args.registry_ref,
168 registry_section: args.registry_section,
169 }
170 }
171}