Add CLA to CLI.
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.
Note
If not otherwise speficied the CLA belongs to the default group “zero” that is the group of non-grouped CLAs.
Note
If CLA belongs to a not yet present group it is created on the fly.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(command_line_interface), | intent(inout) | :: | self |
CLI data. |
||
character(len=*), | intent(in), | optional | :: | pref |
Prefixing string. |
|
character(len=*), | intent(in), | optional | :: | group |
Name of the grouped CLAs. |
|
integer(kind=I4P), | intent(in), | optional | :: | group_index |
Index of the grouped CLAs. |
|
character(len=*), | intent(in), | optional | :: | switch |
Switch name. |
|
character(len=*), | intent(in), | optional | :: | switch_ab |
Abbreviated switch name. |
|
character(len=*), | intent(in), | optional | :: | help |
Help message describing the CLA. |
|
character(len=*), | intent(in), | optional | :: | help_markdown |
Longer help message, markdown formatted. |
|
character(len=*), | intent(in), | optional | :: | help_color |
ANSI color of help messages. |
|
character(len=*), | intent(in), | optional | :: | help_style |
ANSI style of help messages. |
|
logical, | intent(in), | optional | :: | required |
Flag for set required argument. |
|
logical, | intent(in), | optional | :: | val_required |
Flag for set value required for optional argument. |
|
logical, | intent(in), | optional | :: | positional |
Flag for checking if CLA is a positional or a named CLA. |
|
integer(kind=I4P), | intent(in), | optional | :: | position |
Position of positional CLA. |
|
logical, | intent(in), | optional | :: | hidden |
Flag for hiding CLA, thus it does not compare into help. |
|
character(len=*), | intent(in), | optional | :: | act |
CLA value action. |
|
character(len=*), | intent(in), | optional | :: | def |
Default value. |
|
character(len=*), | intent(in), | optional | :: | nargs |
Number of arguments consumed by CLA. |
|
character(len=*), | intent(in), | optional | :: | choices |
List of allowable values for the argument. |
|
character(len=*), | intent(in), | optional | :: | exclude |
Switch name of the mutually exclusive CLA. |
|
character(len=*), | intent(in), | optional | :: | envvar |
Environment variable from which take value. |
|
integer(kind=I4P), | intent(out), | optional | :: | error |
Error trapping flag. |
subroutine add(self, pref, group, group_index, switch, switch_ab, help, help_markdown, help_color, help_style, & required, val_required, positional, position, hidden, act, def, nargs, choices, exclude, envvar, error) !< Add CLA to CLI. !< !< @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. !< !< @note If not otherwise speficied the CLA belongs to the default group "zero" that is the group of non-grouped CLAs. !< !< @note If CLA belongs to a not yet present group it is created on the fly. class(command_line_interface), intent(inout) :: self !< CLI data. character(*), optional, intent(in) :: pref !< Prefixing string. character(*), optional, intent(in) :: group !< Name of the grouped CLAs. integer(I4P), optional, intent(in) :: group_index !< Index of the grouped CLAs. character(*), optional, intent(in) :: switch !< Switch name. character(*), optional, intent(in) :: switch_ab !< Abbreviated switch name. character(*), optional, intent(in) :: help !< Help message describing the CLA. character(*), optional, intent(in) :: help_color !< ANSI color of help messages. character(*), optional, intent(in) :: help_style !< ANSI style of help messages. character(*), optional, intent(in) :: help_markdown !< Longer help message, markdown formatted. logical, optional, intent(in) :: required !< Flag for set required argument. logical, optional, intent(in) :: val_required !< Flag for set value required for optional argument. logical, optional, intent(in) :: positional !< Flag for checking if CLA is a positional or a named CLA. integer(I4P), optional, intent(in) :: position !< Position of positional CLA. logical, optional, intent(in) :: hidden !< Flag for hiding CLA, thus it does not compare into help. character(*), optional, intent(in) :: act !< CLA value action. character(*), optional, intent(in) :: def !< Default value. character(*), optional, intent(in) :: nargs !< Number of arguments consumed by CLA. character(*), optional, intent(in) :: choices !< List of allowable values for the argument. character(*), optional, intent(in) :: exclude !< Switch name of the mutually exclusive CLA. character(*), optional, intent(in) :: envvar !< Environment variable from which take value. integer(I4P), optional, intent(out) :: error !< Error trapping flag. type(command_line_argument) :: cla !< CLA data. integer(I4P) :: g !< Counter. ! initialize CLA call cla%assign_object(self) if (present(switch)) then cla%switch = switch cla%switch_ab = switch else if (present(switch_ab)) then cla%switch = switch_ab cla%switch_ab = switch_ab endif endif if (present(switch_ab )) cla%switch_ab = switch_ab cla%help = 'Undocumented argument' ; if (present(help )) cla%help = help cla%help_color = '' ; if (present(help_color )) cla%help_color = help_color cla%help_style = '' ; if (present(help_style )) cla%help_style = help_style cla%help_markdown = '' ; if (present(help_markdown)) cla%help_markdown = help_markdown cla%is_required = .false. ; if (present(required )) cla%is_required = required cla%is_val_required = .true. ; if (present(val_required )) cla%is_val_required = val_required cla%is_positional = .false. ; if (present(positional )) cla%is_positional = positional cla%position = 0_I4P ; if (present(position )) cla%position = position cla%is_hidden = .false. ; if (present(hidden )) cla%is_hidden = hidden cla%act = action_store ; if (present(act )) cla%act = trim(adjustl(Upper_Case(act))) if (present(def )) cla%def = def if (present(def )) cla%val = def if (present(nargs )) cla%nargs = nargs if (present(choices )) cla%choices = choices cla%m_exclude = '' ; if (present(exclude )) cla%m_exclude = exclude if (present(envvar )) cla%envvar = envvar call cla%check(pref=pref) ; self%error = cla%error if (self%error/=0) then if (present(error)) error = self%error return endif ! add CLA to CLI if ((.not.present(group)).and.(.not.present(group_index))) then call self%clasg(0)%add(pref=pref, cla=cla) ; self%error = self%clasg(0)%error elseif (present(group)) then if (self%is_defined_group(group=group, g=g)) then call self%clasg(g)%add(pref=pref, cla=cla) ; self%error = self%clasg(g)%error else call self%add_group(group=group) call self%clasg(size(self%clasg,dim=1)-1)%add(pref=pref, cla=cla) ; self%error = self%clasg(size(self%clasg,dim=1)-1)%error endif elseif (present(group_index)) then if (group_index<=size(self%clasg,dim=1)-1) then call self%clasg(group_index)%add(pref=pref, cla=cla) ; self%error = self%clasg(group_index)%error endif endif if (present(error)) error = self%error endsubroutine add