signature Function

private function signature(self, bash_completion, plain)

Get signature.

Type Bound

command_line_argument

Arguments

Type IntentOptional Attributes Name
class(command_line_argument), intent(in) :: self

CLA data.

logical, intent(in), optional :: bash_completion

Return the signature for bash completion.

logical, intent(in), optional :: plain

Return the signature as plain switches list.

Return Value character(len=:), allocatable

Signature.


Calls

proc~~signature~2~~CallsGraph proc~signature~2 flap_command_line_argument_t::command_line_argument%signature cton cton proc~signature~2->cton proc~has_choices flap_command_line_argument_t::command_line_argument%has_choices proc~signature~2->proc~has_choices str str proc~signature~2->str

Called by

proc~~signature~2~~CalledByGraph proc~signature~2 flap_command_line_argument_t::command_line_argument%signature proc~signature flap_command_line_arguments_group_t::command_line_arguments_group%signature proc~signature->proc~signature~2 proc~save_bash_completion flap_command_line_interface_t::command_line_interface%save_bash_completion proc~save_bash_completion->proc~signature proc~signature~3 flap_command_line_interface_t::command_line_interface%signature proc~signature~3->proc~signature proc~usage flap_command_line_arguments_group_t::command_line_arguments_group%usage proc~usage->proc~signature proc~is_required_passed flap_command_line_arguments_group_t::command_line_arguments_group%is_required_passed proc~is_required_passed->proc~usage proc~save_man_page flap_command_line_interface_t::command_line_interface%save_man_page proc~save_man_page->proc~signature~3 proc~usage~3 flap_command_line_interface_t::command_line_interface%usage proc~save_man_page->proc~usage~3 proc~save_usage_to_markdown flap_command_line_interface_t::command_line_interface%save_usage_to_markdown proc~save_usage_to_markdown->proc~signature~3 proc~save_usage_to_markdown->proc~usage~3 proc~usage~3->proc~signature~3 proc~usage~3->proc~usage program~flap_save_bash_completion flap_save_bash_completion program~flap_save_bash_completion->proc~save_bash_completion proc~parse~2 flap_command_line_interface_t::command_line_interface%parse program~flap_save_bash_completion->proc~parse~2 proc~parse~2->proc~is_required_passed proc~parse~2->proc~save_usage_to_markdown proc~parse~2->proc~usage~3 proc~print_usage flap_command_line_interface_t::command_line_interface%print_usage proc~print_usage->proc~usage~3 program~flap_save_man_page flap_save_man_page program~flap_save_man_page->proc~save_man_page none~get~2 flap_command_line_interface_t::command_line_interface%get 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~save_usage_to_markdown program~flap_save_usage_to_markdown->none~get~2 program~flap_test_basic flap_test_basic program~flap_test_basic->proc~save_man_page program~flap_test_basic->proc~parse~2 none~get_varying~2 flap_command_line_interface_t::command_line_interface%get_varying program~flap_test_basic->none~get_varying~2 program~flap_test_basic->none~get~2 proc~fake_call flap_test_group::fake_call proc~fake_call->proc~parse~2 proc~fake_call->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_choices_logical flap_test_choices_logical program~flap_test_choices_logical->proc~parse~2 program~flap_test_choices_logical->none~get~2 program~flap_test_nested flap_test_nested 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~parse~2 program~flap_test_string->none~get~2 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 program~flap_test_group flap_test_group program~flap_test_group->proc~fake_call program~flap_test_action_store flap_test_action_store 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->none~get~2 program~flap_test_duplicated_clas flap_test_duplicated_clas program~flap_test_duplicated_clas->none~get~2 program~flap_test_group_examples flap_test_group_examples program~flap_test_group_examples->none~get~2 program~flap_test_hidden flap_test_hidden program~flap_test_hidden->none~get~2 program~flap_test_ignore_unknown_clas flap_test_ignore_unknown_clas program~flap_test_ignore_unknown_clas->none~get~2 program~flap_test_minimal flap_test_minimal program~flap_test_minimal->none~get~2 program~flap_test_nargs_insufficient flap_test_nargs_insufficient program~flap_test_nargs_insufficient->none~get~2 program~flap_test_nargs_insufficient~2 flap_test_nargs_insufficient program~flap_test_nargs_insufficient~2->none~get~2

Source Code

  function signature(self, bash_completion, plain)
  !< Get signature.
  class(command_line_argument), intent(in) :: self             !< CLA data.
  logical, optional,            intent(in) :: bash_completion  !< Return the signature for bash completion.
  logical, optional,            intent(in) :: plain            !< Return the signature as plain switches list.
  logical                                  :: plain_           !< Return the signature as plain switches list, local var.
  logical                                  :: bash_completion_ !< Return the signature for bash completion, local variable.
  character(len=:), allocatable            :: signature        !< Signature.
  integer(I4P)                             :: nargs            !< Number of arguments consumed by CLA.
  integer(I4P)                             :: a                !< Counter.

  bash_completion_ = .false. ; if (present(bash_completion)) bash_completion_ = bash_completion
  plain_ = .false. ; if (present(plain)) plain_ = plain
  if (.not.self%is_hidden) then
    if (bash_completion_) then
      if (.not.self%is_positional) then
        if (plain_) then
          if (trim(adjustl(self%switch))/=trim(adjustl(self%switch_ab))) then
            signature = ' '//trim(adjustl(self%switch))//' '//trim(adjustl(self%switch_ab))
          else
            signature = ' '//trim(adjustl(self%switch))
          endif
        else
          signature = new_line('a')//'    if [ "$prev" == "'//self%switch//'" ] || [ "$prev" == "'//self%switch_ab//'" ] ; then'
          if (self%has_choices()) then
             signature = signature//new_line('a')//'       COMPREPLY=( $( compgen -W "'//choices(self%choices)//'" -- $cur ) )'
          elseif ((self%act==action_store).or.(self%act==action_store_star)) then
             signature = signature//new_line('a')//'       COMPREPLY=( )'
          endif
          signature = signature//new_line('a')//'       return 0'
          signature = signature//new_line('a')//'    fi'
        endif
        ! if (trim(adjustl(self%switch))/=trim(adjustl(self%switch_ab))) then
          ! if (plain_) then
          !   signature = ' "'//trim(adjustl(self%switch))//'" "'//trim(adjustl(self%switch_ab))//'"'
          ! else
            ! signature = ' '//trim(adjustl(self%switch))//' '//trim(adjustl(self%switch_ab))
          ! endif
        ! else
          ! if (plain_) then
          !   signature = ' "'//trim(adjustl(self%switch))//'"'
          ! else
            ! signature = ' '//trim(adjustl(self%switch))
          ! endif
        ! endif
      endif
    else
      if (self%act==action_store) then
        if (.not.self%is_positional) then
          if (allocated(self%nargs)) then
            select case(self%nargs)
            case('+')
              signature = 'value#1 [value#2 value#3...]'
            case('*')
              signature = '[value#1 value#2 value#3...]'
            case default
              nargs = cton(str=trim(adjustl(self%nargs)),knd=1_I4P)
              signature = ''
              do a=1, nargs
                signature = signature//'value#'//trim(str(a, .true.))//' '
              enddo
            endselect
          else
            signature = 'value'
          endif
          if (.not.self%is_val_required) signature = '['//signature//']'
          if (self%is_required) then
            signature = ' '//trim(adjustl(self%switch))//' '//signature
          else
            signature = ' ['//trim(adjustl(self%switch))//' '//signature//']'
          endif
        else
          if (self%is_required) then
            signature = ' value'
          else
            signature = ' [value]'
          endif
        endif
      elseif (self%act==action_store_star) then
        signature = ' [value]'
      else
        if (self%is_required) then
          signature = ' '//trim(adjustl(self%switch))
        else
          signature = ' ['//trim(adjustl(self%switch))//']'
        endif
      endif
    endif
  else
    signature = ''
  endif
  contains
    pure function choices(choices_c)
    !< Return space-separated choices list from a comma-separated one.
    character(len=*), intent(in)  :: choices_c !< Comma-separated list of choices.
    character(len=len(choices_c)) :: choices   !< Space-separated list of choices.
    integer(I4P)                  :: c         !< Counter.

    choices = choices_c
    do c=1, len(choices)
      if (choices(c:c)==',') choices(c:c) = ' '
    enddo
    endfunction choices
  endfunction signature