szaghi / FLAP

Fortran command Line Arguments Parser for poor people
150 stars 34 forks source link

Man page & markdown built-in switches #99

Open GHNewbiee opened 1 year ago

GHNewbiee commented 1 year ago

After considering the examples in the end, I wonder how the -mp and -md switches would be used if there were also required switches. For example:

$ ./program --required1 'some text' --required2 'some numbers' -mp -md

IMHO, both switches have nothing to do with the "flow" of the program. They both are like -h and -v. They produce a result out of the scope of the main program. Both -mp and -md switches would be built-in like -h and -v taking the progname from cli%init() as file name and 1 or md as file extensions.

If convenient, also two extra arguments manname and mdname would be added to cli%init() in favour of freedom.

Hence, just typing

$ ./program -mp -md

w/o any required switches will be more convenient and elegant.

Of course, current possibility of adding manually extra switches to get man page and markdown file names from CL are still available.

Tia

PS: Having default text for each required switch is not always convenient, especially in case a path is required; setting def = '' requires extra condition to stop the execution of the program.

Examples

...
character(99) :: manpage  !< Man page file name
character(99) :: markdown !< Markdown file name

call cli%init(...)

call cli%add(switch='--manpage',  switch_ab='-mp', help='man page file name', required=.false., act='store', def='program.1')
call cli%add(switch='--markdown', switch_ab='-md', help='markdown file name', required=.false., act='store', def='program.md')

call cli%get(switch='-mp', val=manpage)
call cli%get(switch='-md', val=markdown)

call cli%save_man_page(man_file=trim(manpage))
call cli%save_usage_to_markdown(markdown_file=trim(markdown))
$ ./program -mp -md

OR

...
logical :: manpage  !< Man page file name
logical :: markdown !< Markdown file name

call cli%init(...)

call cli%add(switch='--manpage',  switch_ab='-mp', help='man page file name', required=.false., act='store_true', def='.false.')
call cli%add(switch='--markdown', switch_ab='-md', help='markdown file name', required=.false., act='store_true', def='.false.')

call cli%get(switch='-mp', val=manpage)
call cli%get(switch='-md', val=markdown)

if (man .eqv. .true) call cli%save_man_page(man_file='program.1')
if (md  .eqv. .true) call cli%save_usage_to_markdown(markdown_file='program.md')
$ ./program -mp -md
szaghi commented 1 year ago

@GHNewbiee

Nice suggestion, thank you very much. I'll try to work on it ASAP.

Kind regards

jvdp1 commented 11 months ago

Hi, I support this idea too. Is there some progress on this issue? I could potentially help on this by mimicking the switches -h and -v.