1use clap::{CommandFactory, Parser};
2use clap_complete::{generate, Shell};
3
4#[derive(Parser, Debug)]
5#[command(
6 name = "rgx",
7 version,
8 about = "Terminal regex tester with real-time matching and multi-engine support",
9 long_about = "Test and debug regular expressions without leaving your terminal. Supports 3 engines (Rust regex, fancy-regex, PCRE2), capture group highlighting, plain-English explanations, and replace mode. Useful for remote work, shell pipelines, and engine-specific testing."
10)]
11pub struct Cli {
12 #[arg(value_name = "PATTERN")]
14 pub pattern: Option<String>,
15
16 #[arg(short, long)]
18 pub engine: Option<String>,
19
20 #[arg(short = 'i', long)]
22 pub case_insensitive: bool,
23
24 #[arg(short = 'm', long)]
26 pub multiline: bool,
27
28 #[arg(short = 's', long)]
30 pub dotall: bool,
31
32 #[arg(short = 'u', long)]
34 pub unicode: Option<bool>,
35
36 #[arg(short = 'x', long)]
38 pub extended: bool,
39
40 #[arg(short = 'r', long)]
42 pub replacement: Option<String>,
43
44 #[arg(short = 'f', long)]
46 pub file: Option<String>,
47
48 #[arg(short = 't', long)]
50 pub text: Option<String>,
51
52 #[arg(short = 'l', long, conflicts_with = "workspace")]
54 pub load: Option<String>,
55
56 #[arg(short = 'w', long, conflicts_with = "load")]
58 pub workspace: Option<String>,
59
60 #[arg(short = 'p', long)]
63 pub print: bool,
64
65 #[arg(short = 'P', long, conflicts_with = "print")]
68 pub output_pattern: bool,
69
70 #[arg(short = 'g', long, requires = "print", conflicts_with = "count")]
73 pub group: Option<String>,
74
75 #[arg(short = 'c', long, requires = "print", conflicts_with = "group")]
77 pub count: bool,
78
79 #[arg(long, requires = "print")]
81 pub json: bool,
82
83 #[arg(long, default_value = "auto", requires = "print")]
85 pub color: ColorMode,
86
87 #[arg(long)]
89 pub rounded: bool,
90
91 #[arg(long)]
93 pub vim: bool,
94
95 #[arg(long, value_name = "SHELL")]
97 pub completions: Option<Shell>,
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
101pub enum ColorMode {
102 Auto,
103 Always,
104 Never,
105}
106
107impl Cli {
108 pub fn print_completions(shell: Shell) {
109 let mut cmd = Self::command();
110 generate(shell, &mut cmd, "rgx", &mut std::io::stdout());
111 }
112}