pub enum RGArgKind {
Positional {
value_name: &'static str,
multiple: bool,
},
Switch {
long: &'static str,
short: Option<&'static str>,
multiple: bool,
},
Flag {
long: &'static str,
short: Option<&'static str>,
value_name: &'static str,
multiple: bool,
possible_values: Vec<&'static str>,
},
}
Expand description
The kind of a ripgrep argument.
This can be one of three possibilities: a positional argument, a boolean switch flag or a flag that accepts exactly one argument. Each variant stores argument type specific data.
Note that clap supports more types of arguments than this, but we don’t (and probably shouldn’t) use them in ripgrep.
Finally, note that we don’t capture all state about an argument in this type. Some state is only known to clap. There isn’t any particular reason why; the state we do capture is motivated by use cases (like generating documentation).
Variants§
Positional
Fields
value_name: &'static str
The name of the value used in the -h/--help
output. By
convention, this is an all-uppercase string. e.g., PATH
or
PATTERN
.
multiple: bool
Whether an argument can be repeated multiple times or not.
The only argument this applies to is PATH, where an end user can specify multiple paths for ripgrep to search.
If this is disabled, then an argument can only be provided once. For example, PATTERN is one such argument. (Note that the -e/–regexp flag is distinct from the positional PATTERN argument, and it can be provided multiple times.)
A positional argument.
Switch
Fields
multiple: bool
Whether this switch can be provided multiple times where meaning is attached to the number of times this flag is given.
Note that every switch can be provided multiple times. This particular state indicates whether all instances of a switch are relevant or not.
For example, the -u/–unrestricted flag can be provided multiple
times where each repeated use of it indicates more relaxing of
ripgrep’s filtering. Conversely, the -i/–ignore-case flag can
also be provided multiple times, but it is simply considered either
present or not. In these cases, -u/–unrestricted has multiple
set to true
while -i/–ignore-case has multiple
set to false
.
A boolean switch.
Flag
Fields
value_name: &'static str
The name of the value used in the -h/--help
output. By
convention, this is an all-uppercase string. e.g., PATH
or
PATTERN
.
multiple: bool
Whether this flag can be provided multiple times with multiple distinct values.
Note that every flag can be provided multiple times. This particular state indicates whether all instances of a flag are relevant or not.
For example, the -g/–glob flag can be provided multiple times and
all of its values should be interpreted by ripgrep. Conversely,
while the -C/–context flag can also be provided multiple times,
only its last instance is used while all previous instances are
ignored. In these cases, -g/–glob has multiple
set to true
while -C/–context has multiple
set to false
.
A flag the accepts a single value.