pub struct OptionDef {
pub name: String,
pub short: Option<char>,
pub takes_value: bool,
pub multiple: bool,
pub value_name: Option<String>,
pub help: Option<String>,
pub conflicts_with: Vec<String>,
}Expand description
The parse-defining shape of an option — everything that determines how the option is parsed, and nothing about what its values are.
Equality is structural: two attachments of the same option name must
produce equal OptionDefs, or the registry rejects them.
Fields§
§name: StringLong flag, including leading dashes, e.g. "--at". This is the unique
key for the option across the whole project.
short: Option<char>Optional short flag, e.g. 'a'.
takes_value: boolWhether the option takes a value (--at <X>) vs. a boolean flag.
multiple: boolWhether the option may be repeated.
value_name: Option<String>Value placeholder shown in help (e.g. "URL"), when takes_value.
help: Option<String>Help text. Part of the shared definition so the same option reads the same everywhere.
conflicts_with: Vec<String>Long tokens (with dashes) of options this one cannot be combined
with — e.g. an exact --with-dim conflicts with the
--with-min-dim/--with-max-dim range pair. Declaring on one
side is enough: the completion bridge and the parser both
symmetrize. A conflicting flag is withheld from tab-completion
once its counterpart is on the line, and the pair is rejected
at parse time.
Implementations§
Source§impl OptionDef
impl OptionDef
Sourcepub fn conflicts_with(self, others: &[&str]) -> Self
pub fn conflicts_with(self, others: &[&str]) -> Self
Declare options this one cannot be combined with, by long
token (with dashes). One-sided declaration suffices — see the
field docs on OptionDef::conflicts_with.
pub fn short(self, c: char) -> Self
pub fn multiple(self, yes: bool) -> Self
pub fn value_name(self, n: impl Into<String>) -> Self
pub fn help(self, h: impl Into<String>) -> Self
Sourcepub fn parse_sig(&self) -> (bool, bool, Option<char>)
pub fn parse_sig(&self) -> (bool, bool, Option<char>)
The parse-distinguishing signature: the properties that actually change
how the option is parsed — value-taking, repeatable, and the short
spelling. Display-only fields (value_name, help) are excluded, so a
flag that merely documents itself differently across commands is not a
parse inconsistency.