Skip to main content

rgx/config/
cli.rs

1use clap::Parser;
2
3#[derive(Parser, Debug)]
4#[command(
5    name = "rgx",
6    version,
7    about = "regex101, but in your terminal",
8    long_about = "A terminal regex debugger with real-time matching, capture group highlighting, and plain-English explanations."
9)]
10pub struct Cli {
11    /// Initial regex pattern
12    #[arg(value_name = "PATTERN")]
13    pub pattern: Option<String>,
14
15    /// Engine to use: rust, fancy, or pcre2
16    #[arg(short, long, default_value = "rust")]
17    pub engine: String,
18
19    /// Case-insensitive matching
20    #[arg(short = 'i', long)]
21    pub case_insensitive: bool,
22
23    /// Multi-line mode
24    #[arg(short = 'm', long)]
25    pub multiline: bool,
26
27    /// Dot matches newline
28    #[arg(short = 's', long)]
29    pub dotall: bool,
30
31    /// Unicode mode
32    #[arg(short = 'u', long)]
33    pub unicode: bool,
34
35    /// Extended mode (ignore whitespace)
36    #[arg(short = 'x', long)]
37    pub extended: bool,
38}
39
40impl Cli {
41    pub fn parse_engine(&self) -> crate::engine::EngineKind {
42        match self.engine.as_str() {
43            "fancy" => crate::engine::EngineKind::FancyRegex,
44            #[cfg(feature = "pcre2-engine")]
45            "pcre2" => crate::engine::EngineKind::Pcre2,
46            _ => crate::engine::EngineKind::RustRegex,
47        }
48    }
49}