usage Function

private function usage(self, pref, markdown)

Get correct usage.

Type Bound

command_line_argument

Arguments

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

CLAs group data.

character(len=*), intent(in), optional :: pref

Prefixing string.

logical, intent(in), optional :: markdown

Format for markdown

Return Value character(len=:), allocatable

Usage string.


Calls

proc~~usage~2~~CallsGraph proc~usage~2 flap_command_line_argument_t::command_line_argument%usage cton cton proc~usage~2->cton interface~colorize face::colorize proc~usage~2->interface~colorize proc~replace_all flap_utils_m::replace_all proc~usage~2->proc~replace_all str str proc~usage~2->str proc~colorize_default face::colorize_default interface~colorize->proc~colorize_default proc~replace flap_utils_m::replace proc~replace_all->proc~replace proc~wstrip flap_utils_m::wstrip proc~replace_all->proc~wstrip 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~~usage~2~~CalledByGraph proc~usage~2 flap_command_line_argument_t::command_line_argument%usage proc~usage flap_command_line_arguments_group_t::command_line_arguments_group%usage proc~usage->proc~usage~2 proc~is_required_passed flap_command_line_arguments_group_t::command_line_arguments_group%is_required_passed proc~is_required_passed->proc~usage proc~usage~3 flap_command_line_interface_t::command_line_interface%usage proc~usage~3->proc~usage proc~parse~2 flap_command_line_interface_t::command_line_interface%parse proc~parse~2->proc~is_required_passed proc~parse~2->proc~usage~3 proc~save_usage_to_markdown flap_command_line_interface_t::command_line_interface%save_usage_to_markdown proc~parse~2->proc~save_usage_to_markdown proc~print_usage flap_command_line_interface_t::command_line_interface%print_usage proc~print_usage->proc~usage~3 proc~save_man_page flap_command_line_interface_t::command_line_interface%save_man_page proc~save_man_page->proc~usage~3 proc~save_usage_to_markdown->proc~usage~3 proc~fake_call flap_test_group::fake_call 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~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_save_bash_completion flap_save_bash_completion program~flap_save_bash_completion->proc~parse~2 program~flap_save_man_page flap_save_man_page program~flap_save_man_page->proc~save_man_page 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~parse~2 program~flap_test_basic->proc~save_man_page 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 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 usage(self, pref, markdown)
  !< Get correct usage.
  class(command_line_argument), intent(in) :: self       !< CLAs group data.
  character(*), optional,       intent(in) :: pref       !< Prefixing string.
  logical,      optional,       intent(in) :: markdown   !< Format for markdown
  character(len=:), allocatable            :: usage      !< Usage string.
  character(len=:), allocatable            :: prefd      !< Prefixing string.
  character(len=:), allocatable            :: switch_    !< Switch name, local variable.
  character(len=:), allocatable            :: switch_ab_ !< Abbreviated switch name, local variable.
  integer(I4P)                             :: a          !< Counter.
  logical                                  :: markdownd  !< Format for markdown
  integer                                  :: indent     !< how many spaces to indent

  markdownd = .false. ; if (present(markdown)) markdownd = markdown
  indent = 4
  switch_ = colorize(trim(adjustl(self%switch)), color_fg=self%help_color, style=self%help_style)
  switch_ab_ = colorize(trim(adjustl(self%switch_ab)), color_fg=self%help_color, style=self%help_style)
  if (.not.self%is_hidden) then
    if (self%act==action_store) then
      if (.not.self%is_positional) then
        if (allocated(self%nargs)) then
          usage = ''
          select case(self%nargs)
          case('+')
            usage = usage//' value#1 [value#2...]'
          case('*')
            usage = usage//' [value#1 value#2...]'
          case default
            do a=1, cton(str=trim(adjustl(self%nargs)),knd=1_I4P)
              usage = usage//' value#'//trim(str(a, .true.))
            enddo
          endselect
          if (trim(adjustl(self%switch))/=trim(adjustl(self%switch_ab))) then
            if (markdownd) then
              usage = new_line('a')//'* `'//trim(adjustl(self%switch))//usage//'`, `'//trim(adjustl(self%switch_ab))//usage//'`  '
            else
              usage = '   '//switch_//usage//', '//switch_ab_//usage
            endif
          else
            if (markdownd) then
              usage = new_line('a')//'* `'//trim(adjustl(self%switch))//usage//'`  '
            else
              usage = '   '//switch_//usage
            endif
          endif
        else
          if (trim(adjustl(self%switch))/=trim(adjustl(self%switch_ab))) then
            if (markdownd) then
              usage = new_line('a')//'* `'//trim(adjustl(self%switch))//' value`, `'//trim(adjustl(self%switch_ab))//' value'//'`  '
            else
              usage = '   '//switch_//' value, '//switch_ab_//' value'
            endif
          else
            if (markdownd) then
              usage = new_line('a')//'* `'//trim(adjustl(self%switch))//' value`  '
            else
              usage = '   '//switch_//' value'
            endif
          endif
        endif
      else
        if (markdownd) then
          usage = new_line('a')//'* value'
        else
          usage = '  value'
        endif
      endif
      if (allocated(self%choices)) then
        usage = usage//', value in: `'//self%choices//'`'
      endif
    elseif (self%act==action_store_star) then
      usage = '  [value]'
      if (allocated(self%choices)) then
        usage = usage//', value in: ('//self%choices//')'
      endif
    else
      if (trim(adjustl(self%switch))/=trim(adjustl(self%switch_ab))) then
        if (markdownd) then
          usage = new_line('a')//'* `'//trim(adjustl(self%switch))//'`, `'//trim(adjustl(self%switch_ab))//'`  '
        else
          usage = '   '//switch_//', '//switch_ab_
        endif
      else
        if (markdownd) then
          usage = new_line('a')//'* `'//trim(adjustl(self%switch))//'`  '
        else
          usage = '   '//switch_
        endif
      endif
    endif
    prefd = '' ; if (present(pref)) prefd = pref
    usage = prefd//usage
    if (self%is_positional)then
      ! two spaces make a line break in markdown.
      if (markdownd) then
        usage = usage//'  '
      endif
      usage = usage//new_line('a')//prefd//repeat(' ',4)//trim(str(self%position, .true.))//&
       '-th argument'
    endif
    if (allocated(self%envvar)) then
      if (self%envvar /= '') then
        usage = usage//new_line('a')//prefd//repeat(' ',10)//'environment variable name "'//trim(adjustl(self%envvar))//'"'
      endif
    endif
    if (.not.self%is_required) then
      if (self%def /= '') then
        if (markdownd) then
          ! two spaces make a line break in markdown.
          usage = usage//'  '//new_line('a')//prefd//repeat(' ', 4)//'default value '//trim(replace_all(self%def,ARGS_SEP,' '))
        else
          usage = usage//new_line('a')//prefd//repeat(' ', indent)//'default value '//trim(replace_all(self%def,ARGS_SEP,' '))
        endif
      endif
    endif
    if (self%m_exclude/='') usage = usage//new_line('a')//prefd//repeat(' ', indent)//'mutually exclude "'//self%m_exclude//'"'
    if (markdownd) then
      usage = usage//'  '//new_line('a')//prefd//repeat(' ',4)//trim(adjustl(self%help))//'  '
      if (self%help_markdown/='') then
        usage = usage//trim(adjustl(self%help_markdown))//'  '
      endif
    else
      usage = usage//new_line('a')//prefd//repeat(' ', indent)//trim(adjustl(self%help))
    endif
  else
    usage = ''
  endif
  endfunction usage