FORCES
FORtran lib for Comp. Env. Sys.
|
This is a parser for command line arguments. More...
Public Member Functions | |
procedure | add_option (self, name, s_name, help, has_value, value_name, default, required, blank, repeated) |
Add a new option to the cli_parser. | |
procedure | get_option (self, name) |
Get an option from cli_parser by name. | |
procedure | get_option_index (self, name, long, short, raise_error) |
Get the option index from cli_parser by name. | |
procedure | cnt_options (self) |
Get option count from the cli_parser. | |
procedure | option_was_read (self, name) |
Whether the option was read by the cli_parser given by name. | |
procedure | option_read_count (self, name) |
Read count for the option in the cli_parser given by name. | |
procedure | has_option (self, name) |
Whether the option is defined in cli_parser given by name. | |
procedure | get_blank_option_index (self) |
Get the index of the blank option. | |
procedure | option_value (self, name) |
Get the parsed value from an option by name from the cli_parser. | |
procedure | print_help (self) |
Print help message for the cli_parser. | |
procedure | parse (self) |
Parse the given command line arguments with the cli_parser. | |
Public Attributes | |
character(:), allocatable | prog |
Program name (default will be arg(0)). | |
character(:), allocatable | description |
help text for the cli | |
character(:), allocatable | version |
Program version. | |
logical | has_help = .true. |
whether the parser cares about the help text (–help / -h) | |
logical | has_version = .false. |
whether the parser cares about the version text (–version / -V) | |
logical | has_blank_option = .false. |
whether the parser has a blank option. | |
logical | has_logger = .false. |
whether the parser should setup the logger. | |
type(option), dimension(:), allocatable | options |
defined options | |
This is a parser for 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/. Definition at line 100 of file mo_cli.f90.
procedure mo_cli::cli_parser::add_option | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name, | ||
character(1), intent(in), optional | s_name, | ||
character(*), intent(in), optional | help, | ||
logical, intent(in), optional | has_value, | ||
character(*), intent(in), optional | value_name, | ||
character(*), intent(in), optional | default, | ||
logical, intent(in), optional | required, | ||
logical, intent(in), optional | blank, | ||
logical, intent(in), optional | repeated | ||
) |
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 111 of file mo_cli.f90.
procedure mo_cli::cli_parser::cnt_options | ( | class(cli_parser), intent(inout) | self | ) |
Get option count from the cli_parser.
Definition at line 117 of file mo_cli.f90.
procedure mo_cli::cli_parser::get_blank_option_index | ( | class(cli_parser), intent(inout) | self | ) |
Get the index of the blank option.
Definition at line 125 of file mo_cli.f90.
procedure mo_cli::cli_parser::get_option | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name | ||
) |
Get an option from cli_parser by name.
[in] | name | name (long or short) of the desired option |
Definition at line 113 of file mo_cli.f90.
procedure mo_cli::cli_parser::get_option_index | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name, | ||
logical, intent(in), optional | long, | ||
logical, intent(in), optional | short, | ||
logical, intent(in), optional | raise_error | ||
) |
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 115 of file mo_cli.f90.
procedure mo_cli::cli_parser::has_option | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name | ||
) |
Whether the option is defined in cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 123 of file mo_cli.f90.
procedure mo_cli::cli_parser::option_read_count | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name | ||
) |
Read count for the option in the cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 121 of file mo_cli.f90.
procedure mo_cli::cli_parser::option_value | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name | ||
) |
Get the parsed value from an option by name from the cli_parser.
[in] | name | name of the desired option |
Definition at line 127 of file mo_cli.f90.
procedure mo_cli::cli_parser::option_was_read | ( | class(cli_parser), intent(inout) | self, |
character(*), intent(in) | name | ||
) |
Whether the option was read by the cli_parser given by name.
[in] | name | name of the desired option |
Definition at line 119 of file mo_cli.f90.
procedure mo_cli::cli_parser::parse | ( | class(cli_parser), intent(inout) | self | ) |
Parse the given command line arguments with the cli_parser.
Definition at line 131 of file mo_cli.f90.
procedure mo_cli::cli_parser::print_help | ( | class(cli_parser), intent(inout) | self | ) |
Print help message for the cli_parser.
Definition at line 129 of file mo_cli.f90.
character(:), allocatable mo_cli::cli_parser::description |
help text for the cli
Definition at line 102 of file mo_cli.f90.
logical mo_cli::cli_parser::has_blank_option = .false. |
whether the parser has a blank option.
Definition at line 106 of file mo_cli.f90.
logical mo_cli::cli_parser::has_help = .true. |
whether the parser cares about the help text (–help / -h)
Definition at line 104 of file mo_cli.f90.
logical mo_cli::cli_parser::has_logger = .false. |
whether the parser should setup the logger.
Definition at line 107 of file mo_cli.f90.
logical mo_cli::cli_parser::has_version = .false. |
whether the parser cares about the version text (–version / -V)
Definition at line 105 of file mo_cli.f90.
type(option), dimension(:), allocatable mo_cli::cli_parser::options |
defined options
Definition at line 108 of file mo_cli.f90.
character(:), allocatable mo_cli::cli_parser::prog |
Program name (default will be arg(0)).
Definition at line 101 of file mo_cli.f90.
character(:), allocatable mo_cli::cli_parser::version |
Program version.
Definition at line 103 of file mo_cli.f90.