docs(cookbook): Allow repeated operators

This commit is contained in:
Ed Page 2024-01-08 09:50:40 -06:00
parent 148e102ac3
commit d63106b9f6
2 changed files with 74 additions and 16 deletions

View file

@ -11,13 +11,15 @@ Options:
-V, --version Print version
TESTS:
--empty File is empty and is either a regular file or a directory
--name <NAME> Base of file name (the path with the leading directories removed) matches shell
pattern pattern
--empty [<empty>] File is empty and is either a regular file or a directory [default: false]
[possible values: true, false]
--name <name> Base of file name (the path with the leading directories removed) matches
shell pattern pattern
OPERATORS:
-o, --or expr2 is not evaluate if exp1 is true
-a, --and Same as `expr1 expr1`
-o, --or [<or>] expr2 is not evaluate if exp1 is true [default: false] [possible values: true,
false]
-a, --and [<and>] Same as `expr1 expr1` [default: false] [possible values: true, false]
$ find --empty -o --name .keep
[
@ -42,12 +44,38 @@ $ find --empty -o --name .keep
]
$ find --empty -o --name .keep -o --name foo
? 2
error: the argument '--or' cannot be used multiple times
Usage: find [OPTIONS]
For more information, try '--help'.
[
(
"empty",
Bool(
true,
),
),
(
"or",
Bool(
true,
),
),
(
"name",
String(
".keep",
),
),
(
"or",
Bool(
true,
),
),
(
"name",
String(
"foo",
),
),
]
```

View file

@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use clap::{arg, command, ArgGroup, ArgMatches, Command};
use clap::{command, value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command};
fn main() {
let matches = cli().get_matches();
@ -13,14 +13,44 @@ fn cli() -> Command {
.group(ArgGroup::new("tests").multiple(true))
.next_help_heading("TESTS")
.args([
arg!(--empty "File is empty and is either a regular file or a directory").group("tests"),
arg!(--name <NAME> "Base of file name (the path with the leading directories removed) matches shell pattern pattern").group("tests"),
Arg::new("empty")
.long("empty")
.num_args(0)
.value_parser(value_parser!(bool))
.default_missing_value("true")
.default_value("false")
.action(ArgAction::Append)
.help("File is empty and is either a regular file or a directory")
.group("tests"),
Arg::new("name")
.long("name")
.action(ArgAction::Append)
.help("Base of file name (the path with the leading directories removed) matches shell pattern pattern")
.group("tests")
])
.group(ArgGroup::new("operators").multiple(true))
.next_help_heading("OPERATORS")
.args([
arg!(-o - -or "expr2 is not evaluate if exp1 is true").group("operators"),
arg!(-a - -and "Same as `expr1 expr1`").group("operators"),
Arg::new("or")
.short('o')
.long("or")
.num_args(0)
.value_parser(value_parser!(bool))
.default_missing_value("true")
.default_value("false")
.action(ArgAction::Append)
.help("expr2 is not evaluate if exp1 is true")
.group("operators"),
Arg::new("and")
.short('a')
.long("and")
.num_args(0)
.value_parser(value_parser!(bool))
.default_missing_value("true")
.default_value("false")
.action(ArgAction::Append)
.help("Same as `expr1 expr1`")
.group("operators"),
])
}