pub struct Flag<'a> {Show 20 fields
pub key: u64,
pub binding_key: u64,
pub binding_type: Option<BindingType>,
pub name: &'a str,
pub longs: &'a [&'a str],
pub shorts: &'a [u8],
pub negate: Option<&'a str>,
pub takes_value: bool,
pub variadic: bool,
pub var_max: Option<u32>,
pub delimiter: Option<u8>,
pub allow_hyphen_values: bool,
pub allow_negative_numbers: bool,
pub value_terminator: Option<&'a [u8]>,
pub require_equals: bool,
pub value_optional: bool,
pub bool_value: bool,
pub default_missing: Option<&'a [u8]>,
pub global: bool,
pub action: ArgAction,
}Expand description
A flag, addressed by any of its long or short forms.
Fields§
§key: u64Caller-assigned identifier, echoed back in Event::Flag. This is how
generated code knows which field to assign without any string comparison.
See Command::key on why it is this wide.
binding_key: u64Compatibility key for mirroring a redeclared child global into an ancestor field.
Zero means no typed binding contract is declared. Derive-generated tables hash the binding shape and portable metadata so only equivalent bindings receive the same event.
binding_type: Option<BindingType>Resolved Rust value type for a derive-generated binding.
This is separate from Self::binding_key because token spellings are not type
identities: an imported alias and a fully qualified path can name the same type.
name: &'a strUnused by binding, kept so a table entry can carry its own name for diagnostics.
longs: &'a [&'a str]Long forms, written without the leading --.
shorts: &'a [u8]Short forms, as single bytes.
Should be ASCII. A cluster like -xyz is walked one byte at a time, so a
non-ASCII short can never be matched, and the remainder after a value-taking one —
which becomes its value — would begin in the middle of a character.
#[derive(Cli)] rejects a non-ASCII short; a table written by hand should keep to
it. Nothing is unsound if it does not: the value would simply be cut in a place that
makes no sense, and on Windows would then fail to convert.
negate: Option<&'a str>A long form that sets the flag to false, written without the --.
takes_value: boolWhether the flag takes a value.
variadic: boolWhether one occurrence of this flag keeps taking values, until a flag-like token or the end of the command line.
This is the spec’s variadic flag argument (--include <pattern>...). It
is not the spec’s flag-level var=#true, which means the flag may be
repeated and takes one value each time — repetition needs nothing from the
parser, since it already reports every occurrence separately. Conflating
the two makes a merely repeatable flag greedy enough to eat a positional.
var_max: Option<u32>How many values one variadic occurrence may take, after which the next word belongs to whatever comes next.
Only for variadic. A merely repeatable flag — the spec’s
var=#true — is bounded on how many times it was given, which no single token
can decide, so that bound stays with the metadata and is checked after the parse.
delimiter: Option<u8>The byte that makes one word several values, if the flag declares one.
Here rather than with the metadata for the same reason var_max
is: it decides where a word lands. A bound counts values, and a delimiter is what
makes a word stop being one of them — --include a,b,c is three, so a var_max of
two is already past its bound on the single word it was entitled to take. Binding
cannot count without it.
allow_hyphen_values: boolWhether a detached value may itself look like a flag.
The default is to refuse: --jobs --force is far more likely a forgotten
value than a jobs of "--force". Declared, the next token is taken
whatever it looks like — including -- — which is clap’s
allow_hyphen_values and the spec’s property of the same name. A variadic
occurrence still stops collecting at a later flag-like token, so a second
occurrence of the flag is not eaten as a value.
allow_negative_numbers: boolWhether a detached value may be a negative number while other flag-like tokens still stop collection or report as flags.
value_terminator: Option<&'a [u8]>A token that ends one variadic occurrence without becoming a value.
require_equals: boolWhether the value must be attached with =.
--flag=value is accepted and --flag value is not, which is clap’s
require_equals and the spec’s property of the same name. A short’s
attached form (-i9229, -i=9229) still binds: only the following word
is refused.
value_optional: boolWhether this value-taking flag may be present without a value.
A missing value emits the flag event with value: None; bindings such as
Option<Option<T>> can therefore distinguish an absent flag from a bare
flag and from a flag with an explicit value.
bool_value: boolWhether a boolean long flag accepts an attached true or false value.
This does not make the flag value-taking in the ordinary sense: a detached
word is never consumed, and help keeps rendering a switch. Only
--flag=true and --flag=false opt into an explicit boolean value.
default_missing: Option<&'a [u8]>Value used when the flag is present but no value is given.
clap’s default_missing_value and the spec’s default_missing. --color
binds this, --color=never binds never, and an absent flag is not bound.
Combined with Self::require_equals, a following word is still refused.
global: boolWhether the flag is recognized by every command beneath the one that declares it.
action: ArgActionWhether this declared flag binds a field or requests a built-in response.