FORCES
FORtran lib for Comp. Env. Sys.
|
Module to parse command line arguments. More...
Data Types | |
module | cli_parser |
This is a parser for command line arguments. More... | |
module | option |
This is a container for a single command line option. More... | |
Functions/Subroutines | |
type(cli_parser) function | new_cli_parser (prog, description, add_help_option, add_version_option, version, add_logger_options) |
Create a new cli_parser. | |
type(option) function | new_option (name, s_name, help, has_value, value_name, default, required, blank, repeated) |
Create a new option. | |
subroutine | add_option (self, name, s_name, help, has_value, value_name, default, required, blank, repeated) |
Add a new option to the cli_parser. | |
integer(i4) function | cnt_options (self) |
Get option count from the cli_parser. | |
logical function | is_given_arg (self, arg) |
check if this option is the given argument. | |
integer(i4) function | get_option_index (self, name, long, short, raise_error) |
Get the option index from cli_parser by name. | |
type(option) function | get_option (self, name) |
Get an option from cli_parser by name. | |
logical function | option_was_read (self, name) |
Whether the option was read by the cli_parser given by name. | |
integer(i4) function | option_read_count (self, name) |
Read count for the option in the cli_parser given by name. | |
logical function | has_option (self, name) |
Whether the option is defined in cli_parser given by name. | |
integer(i4) function | get_blank_option_index (self) |
Get the index of the blank option. | |
character(:) function, allocatable | option_value (self, name) |
Get the parsed value from an option by name from the cli_parser. | |
subroutine | print_info (self) |
Print info for an option. | |
subroutine | print_help (self) |
Print help message for the cli_parser. | |
subroutine | parse (self) |
Parse the given command line arguments with the cli_parser. | |
subroutine | parse_arg (arg, names, counts) |
Parse given argument. | |
integer(i4) function | findchar (array, chr) |
Module to parse command line arguments.
A simple parser for command line arguments. You can define options and then parse the given command. Option can be with or without passed values and they can be set as required.
The following example demonstrates the functionality:
You can call the program with:
As you see, you can automatically create help and version options:
COPYING
and COPYING.LESSER
provided with this software. The complete GNU license text can also be found at http://www.gnu.org/licenses/.
|
private |
Add a new option to the cli_parser.
[in] | name | long name (will be double hyphenated: –opt) |
[in] | s_name | short name (will be hyphenated: -o) |
[in] | help | description of the option |
[in] | has_value | whether the option has a value |
[in] | value_name | name of the value for the help text (default "value") |
[in] | default | default value for this option |
[in] | required | whether the option is required |
[in] | blank | whether the option is passed blank without hyphenated name (only latter one possible) |
[in] | repeated | whether the option can be read repeatedly |
Definition at line 263 of file mo_cli.f90.
|
private |
Get option count from the cli_parser.
Definition at line 305 of file mo_cli.f90.
References cnt_options().
Referenced by cnt_options().
|
private |
Definition at line 653 of file mo_cli.f90.
|
private |
Get the index of the blank option.
Definition at line 412 of file mo_cli.f90.
References get_blank_option_index().
Referenced by get_blank_option_index().
|
private |
Get an option from cli_parser by name.
[in] | name | name (long or short) of the desired option |
Definition at line 359 of file mo_cli.f90.
References get_option().
Referenced by get_option().
|
private |
Get the option index from cli_parser by name.
[in] | name | name of the desired option |
[in] | long | whether to check long name (default: .true.) |
[in] | short | whether to check short name (default: .true.) |
[in] | raise_error | whether to raise an error if option is not found (default: .true.) |
Definition at line 326 of file mo_cli.f90.
References get_option_index().
Referenced by get_option_index().
|
private |
Whether the option is defined in cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 401 of file mo_cli.f90.
References has_option().
Referenced by has_option().
|
private |
check if this option is the given argument.
Definition at line 315 of file mo_cli.f90.
References is_given_arg().
Referenced by is_given_arg().
|
private |
Create a new cli_parser.
[in] | prog | Program name (default will be arg(0)) |
[in] | description | help text for the cli |
[in] | add_help_option | whether to add a help option (–help, -h) |
[in] | add_version_option | whether to add a version option (–version, -V) |
[in] | version | Program version |
[in] | add_logger_options | whether to add a logger options (–verbose, –quite, ...) |
Definition at line 142 of file mo_cli.f90.
References mo_message::error_message(), new_cli_parser(), and mo_os::path_split().
Referenced by new_cli_parser().
|
private |
Create a new option.
[in] | name | long name (will be double hyphenated: –opt) |
[in] | s_name | short name (will be hyphenated: -o) |
[in] | help | description of the option |
[in] | has_value | whether the option has a value |
[in] | value_name | name of the value for the help text (default "value") |
[in] | default | default value for this option |
[in] | required | whether the option is required |
[in] | blank | whether the option is passed blank without hyphenated name (only latter one possible) |
[in] | repeated | whether the option can be read repeatedly |
Definition at line 205 of file mo_cli.f90.
References new_option().
Referenced by new_option().
|
private |
Read count for the option in the cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 387 of file mo_cli.f90.
References option_read_count().
Referenced by option_read_count().
|
private |
Get the parsed value from an option by name from the cli_parser.
[in] | name | name of the desired option |
Definition at line 433 of file mo_cli.f90.
References option_value().
Referenced by option_value().
|
private |
Whether the option was read by the cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 373 of file mo_cli.f90.
References option_was_read().
Referenced by option_was_read().
|
private |
Parse the given command line arguments with the cli_parser.
Definition at line 510 of file mo_cli.f90.
References mo_logging::log_set_config(), and parse_arg().
|
private |
Parse given argument.
Parse a given argument, that starts with an "-", to determine the involved options in case of a multi arg (-xyz).
[out] | names | names of involved options (can be multiple by using combined short names) |
[out] | counts | counts of occurrences of each option |
Definition at line 615 of file mo_cli.f90.
Referenced by parse().
|
private |
Print help message for the cli_parser.
Definition at line 474 of file mo_cli.f90.
|
private |
Print info for an option.
Definition at line 449 of file mo_cli.f90.