Skip to content

flap_command_line_arguments_group_t ​

Command Line Arguments Group (CLAsG) class.

Source: src/lib/flap_command_line_arguments_group_t.f90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
STATUS_PRINT_Vinteger(kind=I4P)parameterPrint version status.
STATUS_PRINT_Hinteger(kind=I4P)parameterPrint help status.
STATUS_PRINT_Minteger(kind=I4P)parameterPrint help status to Markdown file.
STATUS_NO_ARGSinteger(kind=I4P)parameterNo arguments passed, help printed (no_args_is_help).
STATUS_ALTERNATEinteger(kind=I4P)parameterAn alternate action passed: value validation bypassed (F16).
STATUS_SHOW_COMPLETIONinteger(kind=I4P)parameter--show-completion passed (F24).
STATUS_INSTALL_COMPLETIONinteger(kind=I4P)parameter--install-completion passed (F24).
STATUS_PRINT_MANinteger(kind=I4P)parameter--man passed: the man page saved (F29).
ERROR_CONSISTENCYinteger(kind=I4P)parameterCLAs group consistency error.
ERROR_M_EXCLUDEinteger(kind=I4P)parameterTwo mutually exclusive CLAs group have been called.
ERROR_M_EXCLUDE_SETinteger(kind=I4P)parameterTwo members of a mutually exclusive set have been passed.
ERROR_M_EXCLUDE_SET_REQUIREDinteger(kind=I4P)parameterNo member of a required mutually exclusive set passed.
ERROR_M_EXCLUDE_SET_DEFINITIONinteger(kind=I4P)parameterInvalid definition of a mutually exclusive set.
ERROR_POSITION_DUPLICATEinteger(kind=I4P)parameterTwo positional CLAs declared at the same position.
ERROR_POSITION_GAPinteger(kind=I4P)parameterDeclared positions are not 1..N: one is missing.

Derived Types ​

exclusive_set ​

Mutually exclusive set of switches: at most one member may be passed, exactly one if required (F03 of #125).

Components ​

NameTypeAttributesDescription
switchescharacter(len=:)allocatableMembers, by their switch, as a stored list (LIST_SEP).
is_requiredlogicalExactly one member must be passed.

command_line_arguments_group ​

Command Line Arguments Group (CLAsG) class.

CLAsG are useful for building nested commands.

Inheritance

Extends: object

Components ​

NameTypeAttributesDescription
prognamecharacter(len=:)allocatableProgram name.
versioncharacter(len=:)allocatableProgram version.
helpcharacter(len=:)allocatableHelp message.
help_colorcharacter(len=:)allocatableANSI color of help messages.
help_stylecharacter(len=:)allocatableANSI style of help messages.
help_markdowncharacter(len=:)allocatableLonger help message, markdown formatted.
descriptioncharacter(len=:)allocatableDetailed description.
licensecharacter(len=:)allocatableLicense description.
authorscharacter(len=:)allocatableAuthors list.
epilogcharacter(len=:)allocatableEpilogue message.
m_excludecharacter(len=:)allocatableMutually exclude other CLA(s group).
error_messagecharacter(len=:)allocatableMeaningful error message to standard-error.
error_colorcharacter(len=:)allocatableANSI color of error messages.
error_stylecharacter(len=:)allocatableANSI style of error messages.
examplestype(flap_string)allocatableExamples of correct usage (examples(i)%s).
errorinteger(kind=I4P)Error trapping flag.
usage_luninteger(kind=I4P)Output unit to print help/usage messages
version_luninteger(kind=I4P)Output unit to print version message
error_luninteger(kind=I4P)Error unit to print error messages
case_insensitivelogicalMatch switches and command names in any case (F14).
groupcharacter(len=:)allocatableGroup name (command).
Nainteger(kind=I4P)Number of CLA.
Na_requiredinteger(kind=I4P)Number of required command line arguments.
Na_optionalinteger(kind=I4P)Number of optional command line arguments.
clatype(command_line_argument)allocatableCLA list [1:Na].
is_calledlogicalFlag for checking if CLAs group has been passed to CLI.
no_args_is_helplogicalPrint the help when invoked with no arguments.
m_setstype(exclusive_set)allocatableMutually exclusive sets of switches.
deprecatedcharacter(len=:)allocatableDeprecation message of the command (F13).
aliasestype(flap_string)allocatableAliases of the command (F19), aliases(i)%s.

Type-Bound Procedures ​

NameAttributesDescription
error_prefixpass(self)Prefix of error messages.
free_objectpass(self)Free dynamic memory.
print_versionpass(self)Print version.
print_error_messagepass(self)Print meaningful error message.
inherit_errorpass(self)Take the error of another object, with its message.
clear_errorpass(self)Forget the error and its message.
set_examplespass(self)Set examples of correct usage.
assign_objectpass(lhs )Assignment overloading.
freeFree dynamic memory.
is_namedCheck if a name is the name of the group (command) or an alias.
has_aliasCheck if a name is an alias of the group (command).
namesName and aliases of the group (command), separated.
name_countNumber of names of the group (command): 1 + aliases.
has_examplesCheck if the group (command) has examples.
completion_fishFish completion lines of the group (command) and its CLAs.
completion_powershellPowerShell completion tables of the group (command).
examples_textExamples of the group (command), for its help.
name_ofName (1) or alias (2, ...) of the group (command).
checkCheck data consistency.
check_position_gapsCheck that the declared positions have no gap.
is_required_passedCheck if required CLAs are passed.
add_exclusive_setAdd a mutually exclusive set of switches.
check_exclusive_setsCheck the mutually exclusive sets of switches.
check_mapsCheck the KEY=VALUE pairs of the map CLAs.
is_passedCheck if a CLA has been passed.
is_definedCheck if a CLA has been defined.
is_switch_tokenCheck if a command line token names a CLA of the group.
is_action_passedCheck if a CLA with an action has been passed.
match_compact_countMatch the compact form -vvv of a count CLA.
positional_indexIndex of the positional CLA declared at a position.
value_arityNumber of fixed value slots following a switch.
reset_parseForget the result of a parse, keeping the definitions.
resolve_valuesSettle the source of the values not given on the command line.
config_key_indexIndex of the CLA named by a configuration file key.
raise_error_m_excludeRaise error mutually exclusive CLAs passed.
addAdd CLA to CLAsG.
parseParse CLAsG arguments.
usageGet correct CLAsG usage.
signatureGet CLAsG signature.
completion_skipsGet the bash lines skipping the values of the switches (B37).
sanitize_defaultsSanitize default values.
erroredTrig error occurrence and print meaningful message.
check_m_exclusiveCheck if two mutually exclusive CLAs have been passed.
exclusive_set_ofIndex of the mutually exclusive set of a CLA.
exclusive_set_signatureUsage signature of a mutually exclusive set.

Subroutines ​

free ​

Free dynamic memory.

Attributes: elemental

fortran
subroutine free(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.

Call graph

check_maps ​

Check the KEY=VALUE pairs of the map CLAs (F18 of #125), whatever their source; the first error stops.

fortran
subroutine check_maps(self, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

check ​

Check data consistency.

fortran
subroutine check(self, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

check_position_gaps ​

Check that the declared positions are 1..N without gaps (B29 of #125, D20).

Checked when parsing starts, not in add: positionals may be declared in any order.

fortran
subroutine check_position_gaps(self, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

is_required_passed ​

Check if required CLAs are passed; a missing one prints the group help after its message, unless print_usage is false (the CLI prints the usage line, or nothing: init(usage_on_error=), F27).

fortran
subroutine is_required_passed(self, pref, print_usage)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.
print_usagelogicalinoptionalPrint the group help after the error (default).

Call graph

add_exclusive_set ​

Add a mutually exclusive set of switches (F03 of #125): at most one member may be passed, exactly one if required.

The members are comma separated and must be already defined, named switches (by switch or abbreviation, stored by their switch), not individually required, distinct and in no other set. An invalid set is not added: the error is ERROR_M_EXCLUDE_SET_DEFINITION.

fortran
subroutine add_exclusive_set(self, switches, required, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
switchescharacter(len=*)inComma separated members.
requiredlogicalinoptionalExactly one member must be passed (default .false.).
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

check_exclusive_sets ​

Check the mutually exclusive sets of a called group: at most one member given, exactly one for a required set.

Explicit sources count (command line, environment, configuration file; D2, E3 of #125), a default does not. When a member is on the command line, the environment and configuration values of the other members fall back to their defaults first, so that a value set for a batch job never makes a command line alternative a violation. Called after the statuses (help, version, markdown) and the value resolution, like the required check (E4 of #125).

fortran
subroutine check_exclusive_sets(self, pref, print_usage)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.
print_usagelogicalinoptionalPrint the group help after an error (default).

Call graph

reset_parse ​

Forget the result of a parse (called status, passed values, errors), keeping the definitions.

fortran
subroutine reset_parse(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.

Call graph

resolve_values ​

Settle the source of the values not given on the command line (the value-resolution chain R, F06 of #125).

Called after all groups are parsed, before the required check. The source of a parsed value (command line, or the environment for a bare switch with envvar) is recorded while parsing, so that it survives a parse stopped by an error. The others take, in order, the environment variable if set and not blank (F07), the configuration file (section = group name, key = switch without dashes; F08) if the value is not blank, the default, or nothing.

fortran
subroutine resolve_values(self, ignore_env, config, check_paths, lenient)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
ignore_envlogicalinoptionalTurn every environment lookup off.
configtype(config_file)inoptionalConfiguration file.
check_pathslogicalinoptionalCheck the path values (F09).
lenientlogicalinoptionalIgnore invalid environment lists (alternate, F16).

Call graph

match_compact_count ​

Match the compact form of a count, -vvv (D1 rule 3): a dash and one letter repeated, the letter forming the switch_ab -v of a count CLA. The caller uses it only when no switch matches the whole token (an exact switch wins).

Attributes: pure

fortran
subroutine match_compact_count(self, token, a, n)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
tokencharacter(len=*)inCommand line token.
ainteger(kind=I4P)outIndex of the count CLA, 0 if no match.
ninteger(kind=I4P)outOccurrences (repetitions of the letter).

Call graph

raise_error_m_exclude ​

Raise error mutually exclusive CLAs passed.

fortran
subroutine raise_error_m_exclude(self, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLA data.
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

add ​

Add CLA to CLAs list.

@note If not otherwise declared the action on CLA value is set to "store" a value that must be passed after the switch name or directly passed in case of positional CLA.

fortran
subroutine add(self, pref, cla)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.
clatype(command_line_argument)inCLA data.

Call graph

parse ​

Parse CLAsG arguments.

fortran
subroutine parse(self, args, ignore_unknown_clas, pref, error_unknown_clas, ignore_env, commands)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
argscharacter(len=*)inCommand line arguments.
ignore_unknown_claslogicalinDisable errors-raising for passed unknown CLAs.
prefcharacter(len=*)inoptionalPrefixing string.
error_unknown_clasinteger(kind=I4P)outError flag for passed unknown CLAs.
ignore_envlogicalinoptionalTurn every environment lookup off.
commandstype(flap_string)inoptionalCommand names and aliases (top level), for the

Call graph

errored ​

Trig error occurrence and print meaningful message.

fortran
subroutine errored(self, error, pref, a1, a2, position, members, reason)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
errorinteger(kind=I4P)inError occurred.
prefcharacter(len=*)inoptionalPrefixing string.
a1integer(kind=I4P)inoptionalFirst index CLAs group inconsistent.
a2integer(kind=I4P)inoptionalSecond index CLAs group inconsistent.
positioninteger(kind=I4P)inoptionalPosition of positional CLAs.
memberscharacter(len=*)inoptionalMembers of a mutually exclusive set.
reasoncharacter(len=*)inoptionalWhy a mutually exclusive set is invalid.

Call graph

check_m_exclusive ​

Check if two mutually exclusive CLAs have been passed.

fortran
subroutine check_m_exclusive(self, pref)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.

Call graph

sanitize_defaults ​

Sanitize defaults values.

It is necessary to sanitize the default values of non-passed, optional CLAs. Called or not: the getters read the defaults of a command not called too (#127), and the CLA sanitize is idempotent.

fortran
subroutine sanitize_defaults(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inoutCLAsG data.

Call graph

finalize ​

Free dynamic memory when finalizing.

Attributes: elemental

fortran
subroutine finalize(self)

Arguments

NameTypeIntentAttributesDescription
selftype(command_line_arguments_group)inoutCLAsG data.

Functions ​

is_named ​

Check if a name is the name of the group (command) or one of its aliases (F19 of #125). Trailing blanks are not significant; the case is, unless case_insensitive (F14).

Attributes: pure

Returns: logical

fortran
function is_named(self, name) result(named)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
namecharacter(len=*)inName.

Call graph

has_alias ​

Check if a name is an alias of the group (command) (F19 of #125), with the case rule of is_named.

Attributes: pure

Returns: logical

fortran
function has_alias(self, name) result(alias)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
namecharacter(len=*)inName.

Call graph

completion_fish ​

Get the fish completion lines of the group (F15 of #125): for a command, the line completing its names (while no command is typed) and its CLAs (once it is); for the top level, its CLAs (while no command is typed, if any).

Returns: character(len=:)

fortran
function completion_fish(self, prog, commands) result(lines)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
progcharacter(len=*)inProgram name.
commandslogicalinThe CLI has commands.

Call graph

completion_powershell ​

Get the PowerShell completion table rows of the group (F15 of #125): with commands, its names and aliases mapped to its name ('co' = 'compile'); otherwise its options, as the entry of the options table ('compile' = @(...)).

Returns: character(len=:)

fortran
function completion_powershell(self, commands) result(text)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
commandslogicalinReturn the command rows instead of the options.

Call graph

has_examples ​

Check if the group (command) has examples.

Attributes: pure

Returns: logical

fortran
function has_examples(self) result(has)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.

Call graph

examples_text ​

Return the examples of the group (command) for its help: a blank line, 'Examples:', one example per line.

Attributes: pure

Returns: character(len=:)

fortran
function examples_text(self, prefd) result(text)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
prefdcharacter(len=*)inPrefixing string.

Call graph

name_count ​

Return the number of names of the group (command): its name and its aliases (F19).

Attributes: pure

Returns: integer(kind=I4P)

fortran
function name_count(self) result(n)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.

Call graph

name_of ​

Return the i-th name of the group (command): 1 its name, 2... its aliases (F19).

Attributes: pure

Returns: character(len=:)

fortran
function name_of(self, i) result(name)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
iinteger(kind=I4P)inIndex of the name.

Call graph

names ​

Return the name of the group (command) followed by its aliases, separated by sep (help listing, completion).

Attributes: pure

Returns: character(len=:)

fortran
function names(self, sep) result(list)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
sepcharacter(len=*)inSeparator.

Call graph

is_passed ​

Check if a CLA has been passed.

Attributes: pure

Returns: logical

fortran
function is_passed(self, switch, position)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
switchcharacter(len=*)inoptionalSwitch name.
positioninteger(kind=I4P)inoptionalPosition of positional CLA.

Call graph

positional_index ​

Return the index of the positional CLA declared at a position, 0 if there is none.

Positionals are looked up by their declared position, never by their index in the CLA list.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function positional_index(self, position) result(a)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
positioninteger(kind=I4P)inPosition of the positional CLA.

Call graph

config_key_index ​

Return the index of the CLA named by a configuration file key (its switch without dashes), 0 if none.

Returns: integer(kind=I4P)

fortran
function config_key_index(self, key) result(a)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
keycharacter(len=*)inKey.

Call graph

value_arity ​

Return the number of values that always follow a switch of this group, 0 if not fixed or not a switch.

Fixed: store with a required value (1) or with an integer nargs (N). Not fixed: flags, optional values, environment variables and variadic lists (nargs='+'/'*'), whose extent is decided while parsing.

Returns: integer(kind=I4P)

fortran
function value_arity(self, switch) result(n)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
switchcharacter(len=*)inCommand line argument, maybe a switch.

Call graph

is_defined ​

Check if a CLA has been defined.

Returns: logical

fortran
function is_defined(self, switch, pos)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
switchcharacter(len=*)inSwitch name.
posinteger(kind=I4P)outoptionalCLA position.

Call graph

is_action_passed ​

Check if a CLA with an action (e.g. print help) has been passed.

Attributes: pure

Returns: logical

fortran
function is_action_passed(self, act) result(passed)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
actcharacter(len=*)inAction.

Call graph

is_switch_token ​

Check if a command line token names a CLA of the group, also as NAME=VALUE: the look-ahead test of the parser.

Attributes: pure

Returns: logical

fortran
function is_switch_token(self, token)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
tokencharacter(len=*)inCommand line token.

Call graph

usage ​

Get correct CLAsG usage: the usage line, the description, then the positionals, the required and the optional switches.

One blank line between the parts; the positionals in their own part, in order of position (defects 2, 4, 8 of #126).

Returns: character(len=:)

fortran
function usage(self, pref, no_header, markdown)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
prefcharacter(len=*)inoptionalPrefixing string.
no_headerlogicalinoptionalAvoid insert header to usage.
markdownlogicalinoptionalFormat things form markdown.

Call graph

completion_skips ​

Get the bash case lines skipping the fixed values of the switches of the group (value_arity, as the parser does), so that a value is never taken for a command name by the bash script (B37 of #125); '' if none.

Returns: character(len=:)

fortran
function completion_skips(self) result(lines)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.

Call graph

signature ​

Get CLAsG signature: the usage text, or the bash completion (a COMPREPLY line with the switches, then the value tests).

Returns: character(len=:)

fortran
function signature(self, bash_completion, plain)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
bash_completionlogicalinoptionalReturn the signature for bash completion.
plainlogicalinoptionalReturn the value tests as plain switches lists.

Call graph

exclusive_set_of ​

Return the index of the mutually exclusive set of a CLA, 0 if it is in none.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function exclusive_set_of(self, a) result(s)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
ainteger(kind=I4P)inIndex of the CLA.

Call graph

exclusive_set_signature ​

Return the usage signature of a mutually exclusive set, docopt style: (a | b) if required, [a | b] otherwise.

Returns: character(len=:)

fortran
function exclusive_set_signature(self, s) result(signature)

Arguments

NameTypeIntentAttributesDescription
selfclass(command_line_arguments_group)inCLAsG data.
sinteger(kind=I4P)inIndex of the set.

Call graph

same ​

Compare two names, trailing blanks not significant, in any case with case_insensitive (F14).

Attributes: pure

Returns: logical

fortran
function same(a, b, case_insensitive) result(equal)

Arguments

NameTypeIntentAttributesDescription
acharacter(len=*)inFirst name.
bcharacter(len=*)inSecond name.
case_insensitivelogicalinCompare in any case.

Call graph