add Subroutine

private 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.

Type Bound

command_line_interface

Arguments

Type IntentOptional 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.


Calls

proc~~add~2~~CallsGraph proc~add~2 flap_command_line_interface_t::command_line_interface%add proc~add flap_command_line_arguments_group_t::command_line_arguments_group%add proc~add~2->proc~add proc~add_group flap_command_line_interface_t::command_line_interface%add_group proc~add~2->proc~add_group proc~assign_object flap_object_t::object%assign_object proc~add~2->proc~assign_object proc~check~2 flap_command_line_argument_t::command_line_argument%check proc~add~2->proc~check~2 proc~is_defined_group flap_command_line_interface_t::command_line_interface%is_defined_group proc~add~2->proc~is_defined_group proc~upper_case flap_utils_m::upper_case proc~add~2->proc~upper_case proc~check flap_command_line_arguments_group_t::command_line_arguments_group%check proc~add->proc~check proc~add_group->proc~assign_object proc~add_group->proc~is_defined_group proc~set_examples flap_object_t::object%set_examples proc~add_group->proc~set_examples proc~check_action_consistency flap_command_line_argument_t::command_line_argument%check_action_consistency proc~check~2->proc~check_action_consistency proc~check_envvar_consistency flap_command_line_argument_t::command_line_argument%check_envvar_consistency proc~check~2->proc~check_envvar_consistency proc~check_m_exclude_consistency flap_command_line_argument_t::command_line_argument%check_m_exclude_consistency proc~check~2->proc~check_m_exclude_consistency proc~check_named_consistency flap_command_line_argument_t::command_line_argument%check_named_consistency proc~check~2->proc~check_named_consistency proc~check_optional_consistency flap_command_line_argument_t::command_line_argument%check_optional_consistency proc~check~2->proc~check_optional_consistency proc~check_positional_consistency flap_command_line_argument_t::command_line_argument%check_positional_consistency proc~check~2->proc~check_positional_consistency proc~errored flap_command_line_arguments_group_t::command_line_arguments_group%errored proc~check->proc~errored proc~is_defined flap_command_line_arguments_group_t::command_line_arguments_group%is_defined proc~check->proc~is_defined proc~errored~2 flap_command_line_argument_t::command_line_argument%errored proc~check_action_consistency->proc~errored~2 proc~check_envvar_consistency->proc~errored~2 proc~check_m_exclude_consistency->proc~errored~2 proc~check_named_consistency->proc~errored~2 proc~check_optional_consistency->proc~errored~2 proc~check_positional_consistency->proc~errored~2 interface~colorize face::colorize proc~errored->interface~colorize proc~print_error_message flap_object_t::object%print_error_message proc~errored->proc~print_error_message str str proc~errored->str proc~errored~2->interface~colorize proc~errored~2->proc~print_error_message proc~errored~2->str proc~colorize_default face::colorize_default interface~colorize->proc~colorize_default proc~color_index face::color_index proc~colorize_default->proc~color_index proc~style_index face::style_index proc~colorize_default->proc~style_index proc~upper face::upper proc~colorize_default->proc~upper

Called by

proc~~add~2~~CalledByGraph proc~add~2 flap_command_line_interface_t::command_line_interface%add proc~fake_call flap_test_group::fake_call proc~fake_call->proc~add~2 proc~parse~2 flap_command_line_interface_t::command_line_interface%parse proc~fake_call->proc~parse~2 none~get~2 flap_command_line_interface_t::command_line_interface%get proc~fake_call->none~get~2 proc~parse~2->proc~add~2 program~flap_save_bash_completion flap_save_bash_completion program~flap_save_bash_completion->proc~add~2 program~flap_save_bash_completion->proc~parse~2 program~flap_save_man_page flap_save_man_page program~flap_save_man_page->proc~add~2 program~flap_save_man_page->none~get~2 program~flap_save_usage_to_markdown flap_save_usage_to_markdown program~flap_save_usage_to_markdown->proc~add~2 program~flap_save_usage_to_markdown->none~get~2 program~flap_test_action_store flap_test_action_store program~flap_test_action_store->proc~add~2 none~get_varying~2 flap_command_line_interface_t::command_line_interface%get_varying program~flap_test_action_store->none~get_varying~2 program~flap_test_action_store->none~get~2 program~flap_test_ansi_color_style flap_test_ansi_color_style program~flap_test_ansi_color_style->proc~add~2 program~flap_test_ansi_color_style->none~get~2 program~flap_test_basic flap_test_basic program~flap_test_basic->proc~add~2 program~flap_test_basic->proc~parse~2 program~flap_test_basic->none~get_varying~2 program~flap_test_basic->none~get~2 program~flap_test_choices_logical flap_test_choices_logical program~flap_test_choices_logical->proc~add~2 program~flap_test_choices_logical->proc~parse~2 program~flap_test_choices_logical->none~get~2 program~flap_test_duplicated_clas flap_test_duplicated_clas program~flap_test_duplicated_clas->proc~add~2 program~flap_test_duplicated_clas->none~get~2 program~flap_test_group_examples flap_test_group_examples program~flap_test_group_examples->proc~add~2 program~flap_test_group_examples->none~get~2 program~flap_test_hidden flap_test_hidden program~flap_test_hidden->proc~add~2 program~flap_test_hidden->none~get~2 program~flap_test_ignore_unknown_clas flap_test_ignore_unknown_clas program~flap_test_ignore_unknown_clas->proc~add~2 program~flap_test_ignore_unknown_clas->none~get~2 program~flap_test_minimal flap_test_minimal program~flap_test_minimal->proc~add~2 program~flap_test_minimal->none~get~2 program~flap_test_nargs_insufficient flap_test_nargs_insufficient program~flap_test_nargs_insufficient->proc~add~2 program~flap_test_nargs_insufficient->none~get~2 program~flap_test_nargs_insufficient~2 flap_test_nargs_insufficient program~flap_test_nargs_insufficient~2->proc~add~2 program~flap_test_nargs_insufficient~2->none~get~2 program~flap_test_nested flap_test_nested program~flap_test_nested->proc~add~2 program~flap_test_nested->proc~parse~2 program~flap_test_nested->none~get~2 program~flap_test_string flap_test_string program~flap_test_string->proc~add~2 program~flap_test_string->proc~parse~2 program~flap_test_string->none~get~2 proc~get_cla_list_varying_char~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_char proc~get_cla_list_varying_char~2->proc~parse~2 proc~get_cla_list_varying_i1p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_I1P proc~get_cla_list_varying_i1p~2->proc~parse~2 proc~get_cla_list_varying_i2p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_I2P proc~get_cla_list_varying_i2p~2->proc~parse~2 proc~get_cla_list_varying_i4p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_I4P proc~get_cla_list_varying_i4p~2->proc~parse~2 proc~get_cla_list_varying_i8p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_I8P proc~get_cla_list_varying_i8p~2->proc~parse~2 proc~get_cla_list_varying_logical~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_logical proc~get_cla_list_varying_logical~2->proc~parse~2 proc~get_cla_list_varying_r16p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_R16P proc~get_cla_list_varying_r16p~2->proc~parse~2 proc~get_cla_list_varying_r4p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_R4P proc~get_cla_list_varying_r4p~2->proc~parse~2 proc~get_cla_list_varying_r8p~2 flap_command_line_interface_t::command_line_interface%get_cla_list_varying_R8P proc~get_cla_list_varying_r8p~2->proc~parse~2 proc~get_cla_list~2 flap_command_line_interface_t::command_line_interface%get_cla_list proc~get_cla_list~2->proc~parse~2 proc~get_cla~2 flap_command_line_interface_t::command_line_interface%get_cla proc~get_cla~2->proc~parse~2 program~flap_test_group flap_test_group program~flap_test_group->proc~fake_call none~get_varying~2->proc~get_cla_list_varying_char~2 none~get_varying~2->proc~get_cla_list_varying_i1p~2 none~get_varying~2->proc~get_cla_list_varying_i2p~2 none~get_varying~2->proc~get_cla_list_varying_i4p~2 none~get_varying~2->proc~get_cla_list_varying_i8p~2 none~get_varying~2->proc~get_cla_list_varying_logical~2 none~get_varying~2->proc~get_cla_list_varying_r4p~2 none~get_varying~2->proc~get_cla_list_varying_r8p~2 none~get~2->proc~get_cla_list~2 none~get~2->proc~get_cla~2

Source Code

  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