A command line interface: what is accepted, and what was given.
Declare with set_program, add_option, add_flag and
add_positional; fill with parse or parse_args; read with get,
is_set and occurrences.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | count | = | 0_default_int |
Entries in use; |
|
| type(entry_t), | private, | allocatable | :: | entries(:) |
Declared entries, in registration order, so |
||
| logical, | private | :: | parsed | = | .false. |
Set once a parse has completed, successfully or not. |
|
| type(string_type), | private | :: | program_name |
Name used in the usage line. |
|||
| type(string_type), | private | :: | summary |
One-line description of the program. |
|||
| logical, | private | :: | wants_help | = | .false. |
Set when |
Declare a flag, which takes no value.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name, given on the command line as |
||
| character(len=*), | intent(in) | :: | help |
One-line description. |
||
| character(len=*), | intent(in), | optional | :: | short |
Single-character short name. |
Declare an option that takes a value.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name, given on the command line as |
||
| character(len=*), | intent(in) | :: | help |
One-line description. |
||
| character(len=*), | intent(in), | optional | :: | short |
Single-character short name, given as |
|
| character(len=*), | intent(in), | optional | :: | default |
Value |
Declare a positional argument, filled in registration order.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Name used to read the value back, and in the usage line. |
||
| character(len=*), | intent(in) | :: | help |
One-line description. |
||
| logical, | intent(in), | optional | :: | required |
Whether a parse without it is |
|
| character(len=*), | intent(in), | optional | :: | default |
Value |
Read a value as a string_type.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| type(string_type), | intent(out) | :: | value |
The last value given, or the declared default. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set to |
Read a value into a deferred-length character.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| character(len=:), | intent(out), | allocatable | :: | value |
The last value given, or the declared default. |
|
| type(error_t), | intent(inout), | optional | :: | err |
Set to |
Read a value as integer(int32), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| integer(kind=int32), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as integer(int64), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| integer(kind=int64), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as real(sp), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| real(kind=sp), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as real(dp), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| real(kind=dp), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as logical.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| logical, | intent(out) | :: | value |
Parsed value; false when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unrecognised spelling. |
Whether -h or --help was given.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this |
The help text, as a string. Nothing is printed; see the module note.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this |
Whether name appeared on the command line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name to look for. |
How many times name appeared on the command line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name to look for. |
Parse the real command line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| type(error_t), | intent(inout), | optional | :: | err |
Set on a parse or validation failure. |
Parse an explicit argument list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| type(string_type), | intent(in) | :: | args(:) |
Arguments, excluding the program name. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on a parse or validation failure. |
Name and one-line description, used by help_text.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Program name as it should appear in the usage line. |
||
| character(len=*), | intent(in) | :: | summary |
One-line description of what the program does. |
Index of the entry with this long name, or 0.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name to look for, without dashes. |
Read a value into a deferred-length character.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| character(len=:), | intent(out), | allocatable | :: | value |
The last value given, or the declared default. |
|
| type(error_t), | intent(inout), | optional | :: | err |
Set to |
Read a value as integer(int32), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| integer(kind=int32), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as integer(int64), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| integer(kind=int64), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as logical.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| logical, | intent(out) | :: | value |
Parsed value; false when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unrecognised spelling. |
Read a value as real(dp), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| real(kind=dp), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as real(sp), strictly.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| real(kind=sp), | intent(out) | :: | value |
Parsed value; zero when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unparsable value. |
Read a value as a string_type.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| type(string_type), | intent(out) | :: | value |
The last value given, or the declared default. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set to |
Make room for one more entry, doubling the store when it is full.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this |
type :: cli_t !! A command line interface: what is accepted, and what was given. !! !! Declare with `set_program`, `add_option`, `add_flag` and !! `add_positional`; fill with `parse` or `parse_args`; read with `get`, !! `is_set` and `occurrences`. private type(string_type) :: program_name !! Name used in the usage line. type(string_type) :: summary !! One-line description of the program. type(entry_t), allocatable :: entries(:) !! Declared entries, in registration order, so `help_text` is stable. integer(default_int) :: count = 0_default_int !! Entries in use; `entries` may be longer. logical :: wants_help = .false. !! Set when `-h` or `--help` was seen. logical :: parsed = .false. !! Set once a parse has completed, successfully or not. contains procedure :: set_program => cli_set_program procedure :: add_option => cli_add_option procedure :: add_flag => cli_add_flag procedure :: add_positional => cli_add_positional procedure :: parse => cli_parse procedure :: parse_args => cli_parse_args procedure :: help_requested => cli_help_requested procedure :: help_text => cli_help_text procedure :: is_set => cli_is_set procedure :: occurrences => cli_occurrences procedure :: has => cli_has generic :: get => get_string, get_char, get_int32, get_int64, & get_real_sp, get_real_dp, get_logical procedure, private :: get_string => cli_get_string procedure, private :: get_char => cli_get_char procedure, private :: get_int32 => cli_get_int32 procedure, private :: get_int64 => cli_get_int64 procedure, private :: get_real_sp => cli_get_real_sp procedure, private :: get_real_dp => cli_get_real_dp procedure, private :: get_logical => cli_get_logical procedure, private :: find => cli_find procedure, private :: reserve => cli_reserve end type cli_t