pub struct Spec { /* private fields */ }Expand description
Spec describes a flag, in such a way that the parser can correctly identify it in the set of arguments given on the command-line.
Implementations§
Source§impl Spec
impl Spec
Sourcepub fn required(
name: &str,
help: &str,
short_name: Option<char>,
default_value: Option<&str>,
) -> Spec
pub fn required( name: &str, help: &str, short_name: Option<char>, default_value: Option<&str>, ) -> Spec
Constructs a Spec which describes a required named flag. This flag may have a default value, but the key point is that it must have some value after parsing is complete.
Sourcepub fn optional(name: &str, help: &str, short_name: Option<char>) -> Spec
pub fn optional(name: &str, help: &str, short_name: Option<char>) -> Spec
Constructs a Spec which describes an optional named flag. This flag may not have a value after we are finished parsing.
Sourcepub fn boolean(name: &str, help: &str, short_name: Option<char>) -> Spec
pub fn boolean(name: &str, help: &str, short_name: Option<char>) -> Spec
Constructs a Spec which describes a boolean named flag. Flags of this type always have a value, and that value is either true or false, instead of being a freeform string like other flag types.
If this flag is not specified at all on the command line, its “default value” is false.
Sourcepub fn positional(
name: &str,
help: &str,
default_value: Option<&[&str]>,
is_variadic: bool,
) -> Result<Spec>
pub fn positional( name: &str, help: &str, default_value: Option<&[&str]>, is_variadic: bool, ) -> Result<Spec>
Constructs a Spec which describes a positional flag. Flags of this type are not looked up by name after a “-” or “–” character, but instead are parsed purely by their position in the list of command-line arguments.
This also means that the order in which positional flags are added to a Specs structure matters for parsing.
A positional flag is variadic if it should be able to collect more than one value (e.g., for a command which takes a list of files to process of unspecified length).
Sourcepub fn get_short_name(&self) -> Option<char>
pub fn get_short_name(&self) -> Option<char>
Returns this flag’s short name, if it has one.