Get signature.
Type | Intent | Optional | 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. |
Signature.
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