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