derive(Options) generates an implementation of the trait
creating an option for each field of the decorated
gumdrop documentation for an example
of its usage.
derive(Options) can be controlled by adding
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 type
Tis a type implementing
Options. Typically, this type is an
enumcontaining subcommand option types.
help_flagmarks an option as a help flag. The field must be
booltype. Options named
helpwill 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 all
freefields, in declared sequence. If the final
freefield is of type
Vec<T>, it will contain all remaining free arguments.
short = "?"sets the short option name to the given character
no_shortprevents a short option from being assigned to the field
long = "..."sets the long option name to the given string
no_longprevents a long option from being assigned to the field
defaultprovides 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.
requiredwill cause an error if the option is not present, unless at least one
help_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 to
Vec<T>fields, unless the
no_multioption is present.
no_multiwill inhibit automatically marking
not_requiredwill cancel a type-level
requiredflag (see below).
help = "..."sets help text returned from the
Options::usagemethod; field doc comment may also be provided to set the help text. If both are present, the
helpattribute value is used.
meta = "..."sets the meta variable displayed in usage for options which accept an argument
parse(...)uses a named function to parse a value from a string. Valid parsing function types are:
parse(from_str = "...")for
fn(&str) -> T
parse(try_from_str = "...")for
fn(&str) -> Result<T, E> where E: Display
options attribute may also be added at the type level.
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
Additionally, the following flags may be set at the type level to establish
default values for all contained fields: