usage Function

private function usage(self, g, pref, no_header, no_examples, no_epilog, markdown) result(usaged)

Print correct usage of CLI.

Type Bound

command_line_interface

Arguments

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

CLI data.

integer(kind=I4P), intent(in) :: g

Group index.

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

Prefixing string.

logical, intent(in), optional :: no_header

Avoid insert header to usage.

logical, intent(in), optional :: no_examples

Avoid insert examples to usage.

logical, intent(in), optional :: no_epilog

Avoid insert epilogue to usage.

logical, intent(in), optional :: markdown

Format things with markdown

Return Value character(len=:), allocatable

Usage string.


Calls

proc~~usage~3~~CallsGraph proc~usage~3 flap_command_line_interface_t::command_line_interface%usage proc~signature~3 flap_command_line_interface_t::command_line_interface%signature proc~usage~3->proc~signature~3 proc~usage flap_command_line_arguments_group_t::command_line_arguments_group%usage proc~usage~3->proc~usage proc~signature flap_command_line_arguments_group_t::command_line_arguments_group%signature proc~signature~3->proc~signature proc~usage->proc~signature proc~usage~2 flap_command_line_argument_t::command_line_argument%usage proc~usage->proc~usage~2 proc~signature~2 flap_command_line_argument_t::command_line_argument%signature proc~signature->proc~signature~2 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~signature~2->cton proc~signature~2->str proc~has_choices flap_command_line_argument_t::command_line_argument%has_choices proc~signature~2->proc~has_choices 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~3~~CalledByGraph proc~usage~3 flap_command_line_interface_t::command_line_interface%usage proc~parse~2 flap_command_line_interface_t::command_line_interface%parse 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, g, pref, no_header, no_examples, no_epilog, markdown) result(usaged)
  !< Print correct usage of CLI.
  class(command_line_interface), intent(in) :: self             !< CLI data.
  integer(I4P),                  intent(in) :: g                !< Group index.
  character(*), optional,        intent(in) :: pref             !< Prefixing string.
  logical,      optional,        intent(in) :: no_header        !< Avoid insert header to usage.
  logical,      optional,        intent(in) :: no_examples      !< Avoid insert examples to usage.
  logical,      optional,        intent(in) :: no_epilog        !< Avoid insert epilogue to usage.
  logical,      optional,        intent(in) :: markdown         !< Format things with markdown
  character(len=:), allocatable             :: prefd            !< Prefixing string.
  character(len=:), allocatable             :: usaged           !< Usage string.
  logical                                   :: no_headerd       !< Avoid insert header to usage.
  logical                                   :: no_examplesd     !< Avoid insert examples to usage.
  logical                                   :: no_epilogd       !< Avoid insert epilogue to usage.
  logical                                   :: markdownd        !< Format for markdown.
  logical                                   :: grouped_examples !< Will show examples of group usage.
  integer(I4P)                              :: gi               !< Counter.

  no_headerd = .false. ; if (present(no_header)) no_headerd = no_header
  no_examplesd = .false. ; if (present(no_examples)) no_examplesd = no_examples
  no_epilogd = .false. ; if (present(no_epilog)) no_epilogd = no_epilog
  markdownd = .false. ; if (present(markdown)) markdownd = markdown
  prefd = '' ; if (present(pref)) prefd = pref
  grouped_examples = .false.
  if (g>0) then ! usage of a specific command
    usaged = self%clasg(g)%usage(pref=prefd,no_header=no_headerd,markdown=markdownd)
    if(allocated(self%clasg(g)%examples).and.(.not.no_examplesd)) then
      usaged = usaged//print_examples(prefd, self%clasg(g)%examples)
      grouped_examples = .true.
    endif
  else ! usage of whole CLI
    if (no_headerd) then
      usaged = ''
    else
      usaged = prefd//self%help//self%progname//' '//self%signature()
      if (self%description/='') usaged = usaged//new_line('a')//new_line('a')//prefd//self%description
    endif
    if (self%clasg(0)%Na>0) usaged = usaged//new_line('a')//self%clasg(0)%usage(pref=prefd,no_header=.true.,markdown=markdownd)
    if (size(self%clasg,dim=1)>1) then
      usaged = usaged//new_line('a')//new_line('a')//prefd//'Commands:'
      do gi=1, size(self%clasg,dim=1)-1
        usaged = usaged//new_line('a')//prefd//'  '//self%clasg(gi)%group
        usaged = usaged//new_line('a')//prefd//repeat(' ',10)//self%clasg(gi)%description
      enddo
      usaged = usaged//new_line('a')//new_line('a')//prefd//'For more detailed commands help try:'
      do gi=1,size(self%clasg,dim=1)-1
        usaged = usaged//new_line('a')//prefd//'  '//self%progname//' '//self%clasg(gi)%group//' -h,--help'
      enddo
    endif
  endif
  if (allocated(self%examples).and.(.not.no_examplesd).and.(.not.grouped_examples)) then
    usaged = usaged//print_examples(prefd, self%examples)
  endif
  if (self%epilog/=''.and.(.not.no_epilogd)) usaged = usaged//new_line('a')//prefd//self%epilog

  contains
    function print_examples(prefd, examples) result(exampled)
    !< Print examples of the correct usage.
      character(*),     intent(in)  :: prefd          !< Prefixing string.
      character(*),     intent(in)  :: examples(1:)   !< Examples to be printed.
      character(len=:), allocatable :: exampled       !< Examples string.
      integer(I4P)                  :: e              !< Counter.

      exampled = new_line('a')//new_line('a')//prefd//'Examples:'
      do e=1, size(examples,dim=1)
        exampled = exampled//new_line('a')//prefd//'   '//trim(examples(e))
      enddo
    endfunction print_examples
  endfunction usage