forked from rust-lang/regex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.rs
75 lines (70 loc) · 2.11 KB
/
common.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use lexopt::{Arg, Parser};
use crate::args::{Configurable, Usage};
/// This exposes all of the configuration knobs on a regex_automata::Input via
/// CLI flags. The only aspect of regex_automata::Input that this does not
/// cover is the haystack, which should be provided by other means (usually
/// with `Haystack`).
#[derive(Debug, Default)]
pub struct Config {
pub quiet: bool,
pub verbose: bool,
pub no_table: bool,
}
impl Config {
pub fn table(&self) -> bool {
!self.no_table
}
}
impl Configurable for Config {
fn configure(
&mut self,
_: &mut Parser,
arg: &mut Arg,
) -> anyhow::Result<bool> {
match *arg {
Arg::Short('q') | Arg::Long("quiet") => {
self.quiet = true;
}
Arg::Long("verbose") => {
self.verbose = true;
}
Arg::Long("no-table") => {
self.no_table = true;
}
_ => return Ok(false),
}
Ok(true)
}
fn usage(&self) -> &[Usage] {
const USAGES: &'static [Usage] = &[
Usage::new(
"-q, --quiet",
"Suppress some output.",
r#"
This is a generic flag that suppresses some (but not all) output. Which output
is suppressed depends on the command. For example, using the -q/--quiet flag
with the 'regex-cli debug' variety of commands will only show the properties of
the objected being printed and will suppress the debug printing of the object
itself.
"#,
),
Usage::new(
"--verbose",
"Add more output.",
r#"
This is a generic flag that expands output beyond the "normal" amount. Which
output is added depends on the command.
"#,
),
Usage::new(
"--no-table",
"Omit any table of information from the output.",
r#"
Many commands in this tool will print a table of property information related
to the task being performed. Passing this flag will suppress that table.
"#,
),
];
USAGES
}
}