Class for command-line argument parsing.
Create an arg object, then read and parse the arguments:
character(len=72) :: input
integer :: delay, rc
logical :: verbose
type(arg_class) :: arg
call arg%create()
call arg%add('input', short='i', type=ARG_TYPE_STRING, required=.true.)
call arg%add('delay', short='x', type=ARG_TYPE_INTEGER)
call arg%add('verbose', short='V', type=ARG_TYPE_LOGICAL)
rc = arg%read()
call dm_error_out(rc)
call arg%get('input', input)
call arg%get('delay', delay)
call arg%get('verbose, verbose)
call arg%destroy()
Each argument requires name and type. The default type is
ARG_TYPE_LOGICAL
. The command-line arguments --help
/-h
and
--version
/-v
are processed automatically by method read()
.
Additionally, you can pass a callback routine of abstract interface
dm_arg_version_callback()
to read()
that outputs the version string.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | ARG_TYPE_NONE | = | 0 |
None type (invalid). |
integer, | public, | parameter | :: | ARG_TYPE_LOGICAL | = | 1 |
Logical argument. |
integer, | public, | parameter | :: | ARG_TYPE_INTEGER | = | 2 |
Integer value. |
integer, | public, | parameter | :: | ARG_TYPE_REAL | = | 3 |
Real value. |
integer, | public, | parameter | :: | ARG_TYPE_CHAR | = | 4 |
Single character value. |
integer, | public, | parameter | :: | ARG_TYPE_STRING | = | 5 |
Character string value. |
integer, | public, | parameter | :: | ARG_TYPE_ID | = | 6 |
Valid ID value. |
integer, | public, | parameter | :: | ARG_TYPE_UUID | = | 7 |
Valid UUIDv4 value. |
integer, | public, | parameter | :: | ARG_TYPE_TIME | = | 8 |
Valid ISO 8601 value. |
integer, | public, | parameter | :: | ARG_TYPE_LEVEL | = | 9 |
Log level (name string or integer value). |
integer, | public, | parameter | :: | ARG_TYPE_FILE | = | 10 |
Path to file on file system (must exist). |
integer, | public, | parameter | :: | ARG_TYPE_DATABASE | = | 11 |
Path to database on file system (must exist). |
integer, | public, | parameter | :: | ARG_TYPE_LAST | = | 11 |
Never use this. |
integer, | public, | parameter | :: | ARG_NAME_LEN | = | 32 |
Maximum length of argument name. |
integer, | public, | parameter | :: | ARG_VALUE_LEN | = | FILE_PATH_LEN |
Maximum length of argument value. |
Callback routine that outputs the version information.
Public class to store and parse command-line arguments.
procedure, public :: add => arg_add | |
procedure, public :: create => arg_create | |
procedure, public :: destroy => arg_destroy | |
generic, public :: get => get_int32, get_logical, get_real64, get_string | |
procedure, public :: passed => arg_passed | |
procedure, public :: read => arg_read |