opts :: OptionEnum
Declare an enumeration option with all its possible values as an array.
Once the arguments are processed, value is set as the index of the selected value, if any.
opts :: OptionEnum :: defaultinit
Init a new OptionEnum fromvalues with a help message and names.
opts $ OptionEnum :: SELF
Type of this instance, automatically specialized in every classopts $ OptionEnum :: pretty_default
Pretty print the default value.opts :: OptionParameter :: _parameter_mandatory
Is the parameter mandatory?core :: Object :: class_factory
Implementation used byget_class to create the specific class.
opts :: Option :: default_value=
Default value of this optionopts :: OptionParameter :: defaultinit
opts :: OptionEnum :: defaultinit
Init a new OptionEnum fromvalues with a help message and names.
opts :: Option :: defaultinit
Create a new optioncore :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself and other are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself the same as other in a serialization context?
core :: Object :: is_same_type
Return true ifself and other have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).opts :: OptionParameter :: parameter_mandatory
Is the parameter mandatory?opts :: OptionParameter :: parameter_mandatory=
Is the parameter mandatory?opts :: Option :: read_param
Consume parameters for this option
# An option to choose from an enumeration
#
# Declare an enumeration option with all its possible values as an array.
# Once the arguments are processed, `value` is set as the index of the selected value, if any.
class OptionEnum
super OptionParameter
redef type VALUE: Int
# Values in the enumeration.
var values: Array[String]
# Init a new OptionEnum from `values` with a `help` message and `names`.
#
# `default` is the index of the default value in `values`.
init(values: Array[String], help: String, default: Int, names: String...) is old_style_init do
assert values.length > 0
self.values = values.to_a
super("{help} <{values.join(", ")}>", default, names)
end
redef fun convert(str)
do
var id = values.index_of(str)
if id == -1 then
var e = "Unrecognized value for option {names.join(", ")}.\n"
e += "Expected values are: {values.join(", ")}."
errors.add(e)
end
return id
end
# Get the value name from `values`.
fun value_name: String do return values[value]
redef fun pretty_default
do
return " ({values[default_value]})"
end
end
lib/opts/opts.nit:189,1--227,3