libsim
Versione6.3.0
|
This class allows to parse the command-line options of a program in an object-oriented way, similarly to the optparse class found in Python library. Continua...
This class allows to parse the command-line options of a program in an object-oriented way, similarly to the optparse class found in Python library.
The class handles both GNU-style long options, introduced by a double dash –
and containing any printable ASCII character except the equal sign =
, and the traditional Unix short options, introduced by a single dash -
and containing a single character which can be any printable ASCII character except the dash itself.
Options may require an argument, which can be integer, real, double precision or character, in that case the argument may be given in any of the following ways (long and short options):
–lon=34.5
–lon 34.5
-l34.5
-l 34.5
By default, the argument to an option is compulsory, so any following string, even empty or starting with a dash -
, is interpreted as the argument to the option, while its absence (i.e. end of command line) determines an error condition in the parsing phase. However the argument to character options can be declared as optional in the corresponding definition method; in those cases the following argument, if any, is interpreted as the argument to the option only if it does not start with a dash -
(no chance to quote a dash in these cases); if no optional argument is found, then the variable associated to the option is set to the missing value of the corresponding type, without raising an error condition.
Array options (only for integer, real and double precision) must be provided as comma-separated values, similarly to a record of a csv file, an empty field generates a missing value of the proper type in the resulting array, the length of the array is not a priori limited.
Grouping of short options, like -xvf
is not allowed. When a double dash –
or an argument (which is not an argument to an option) not starting by a dash -
is encountered, the parsing of options stops and the management of the remaining arguments (typically a list of files) is left to the calling program.
Options can be of the following kinds:
If the same option is encountered multiple times on the command line, the value set in the last occurrence takes precedence, the only exception is count options where every repetition increments the corresponding counter by one.
Options are added through the generic optionparser_add method (for character, integer, floating point or logical options, including array variants) or through the specific methods optionparser_add_count, optionparser_add_help optionparser_add_sep (for count, help and separator options).
The effect of command line parsing is to set some desired variables according to the information provided on the command line.
Array options set the values of objects of derived types arrayof_integer, arrayof_real and arrayof_doubleprecision which are dynamically growable 1-d arrays defined in the array_utilities module.
Definizione alla linea 407 del file optionparser_class.F90.