Get correct usage.
Type | Intent | Optional | 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 |
Usage string.
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