[−][src]Crate gumdrop_derive
Provides derive(Options) for gumdrop crate
derive(Options)
derive(Options) generates an implementation of the trait Options,
creating an option for each field of the decorated struct.
See the gumdrop documentation for an example
of its usage.
options attribute
Behavior of derive(Options) can be controlled by adding #[options(...)]
attributes to one or more fields within a decorated struct.
Supported items are:
commandindicates that a field represents a subcommand. The field must be of typeOption<T>whereTis a type implementingOptions. Typically, this type is anenumcontaining subcommand option types.help_flagmarks an option as a help flag. The field must bebooltype. Options namedhelpwill automatically receive this option.no_help_flagprevents an option from being considered a help flag.countmarks a field as a counter value. The field will be incremented each time the option appears in the arguments, i.e.field += 1;freemarks a field as a positional argument field. Non-option arguments will be used to fill allfreefields, in declared sequence. If the finalfreefield is of typeVec<T>, it will contain all remaining free arguments.short = "?"sets the short option name to the given characterno_shortprevents a short option from being assigned to the fieldlong = "..."sets the long option name to the given stringno_longprevents a long option from being assigned to the fielddefaultprovides a default value for the option field. The value of this field is parsed in the same way as argument values.default_exprprovides a default value for the option field. The value of this field is parsed at compile time as a Rust expression and is evaluated before any argument values are processed.
Thedefault_exprfeature must be enabled to use this attribute.requiredwill cause an error if the option is not present, unless at least onehelp_flagoption is also present.multi = "..."will allow parsing an option multiple times, adding each parsed value to the field using the named method. This behavior is automatically applied toVec<T>fields, unless theno_multioption is present.no_multiwill inhibit automatically markingVec<T>fields asmultinot_requiredwill cancel a type-levelrequiredflag (see below).help = "..."sets help text returned from theOptions::usagemethod; field doc comment may also be provided to set the help text. If both are present, thehelpattribute value is used.meta = "..."sets the meta variable displayed in usage for options which accept an argumentparse(...)uses a named function to parse a value from a string. Valid parsing function types are:parse(from_str = "...")forfn(&str) -> Tparse(try_from_str = "...")forfn(&str) -> Result<T, E> where E: Displayparse(from_str)usesstd::convert::From::fromparse(try_from_str)usesstd::str::FromStr::from_str
The options attribute may also be added at the type level.
The help attribute (or a type-level doc comment) can be used to provide
some introductory text which will precede option help text in the usage
string.
Additionally, the following flags may be set at the type level to establish
default values for all contained fields: no_help_flag, no_long,
no_short, and required.
Derive Macros
| Options |