Skip to content

Commit

Permalink
Addition of the default flag --markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdp1 committed Sep 22, 2023
1 parent 5a63132 commit 84e0100
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/lib/flap_command_line_argument_t.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module flap_command_line_argument_t
public :: ACTION_STORE_TRUE
public :: ACTION_STORE_FALSE
public :: ACTION_PRINT_HELP
public :: ACTION_PRINT_MARK
public :: ACTION_PRINT_VERS
public :: ARGS_SEP
public :: ERROR_UNKNOWN
Expand Down Expand Up @@ -102,6 +103,7 @@ module flap_command_line_argument_t
character(len=*), parameter :: ACTION_STORE_TRUE = 'STORE_TRUE' !< Store .true. without the necessity of a value.
character(len=*), parameter :: ACTION_STORE_FALSE = 'STORE_FALSE' !< Store .false. without the necessity of a value.
character(len=*), parameter :: ACTION_PRINT_HELP = 'PRINT_HELP' !< Print help message.
character(len=*), parameter :: ACTION_PRINT_MARK = 'PRINT_MARKDOWN'!< Print help to Markdown file.
character(len=*), parameter :: ACTION_PRINT_VERS = 'PRINT_VERSION' !< Print version.
character(len=*), parameter :: ARGS_SEP = '||!||' !< Arguments separator for multiple valued (list) CLA.

Expand Down Expand Up @@ -657,6 +659,7 @@ subroutine check_action_consistency(self, pref)
self%act/=ACTION_STORE_TRUE.and. &
self%act/=ACTION_STORE_FALSE.and.&
self%act/=ACTION_PRINT_HELP.and. &
self%act/=ACTION_PRINT_MARK.and. &
self%act/=ACTION_PRINT_VERS) then
call self%errored(pref=pref, error=ERROR_ACTION_UNKNOWN)
return
Expand Down
5 changes: 5 additions & 0 deletions src/lib/flap_command_line_arguments_group_t.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module flap_command_line_arguments_group_t
use face, only : colorize
use flap_command_line_argument_t, only : command_line_argument, &
ACTION_PRINT_HELP, &
ACTION_PRINT_MARK, &
ACTION_PRINT_VERS, &
ACTION_STORE, &
ACTION_STORE_STAR, &
Expand All @@ -18,6 +19,7 @@ module flap_command_line_arguments_group_t
public :: command_line_arguments_group
public :: STATUS_PRINT_V
public :: STATUS_PRINT_H
public :: STATUS_PRINT_M

type, extends(object) :: command_line_arguments_group
!< Command Line Arguments Group (CLAsG) class.
Expand Down Expand Up @@ -54,6 +56,7 @@ module flap_command_line_arguments_group_t
! status codes
integer(I4P), parameter :: STATUS_PRINT_V = -1 !< Print version status.
integer(I4P), parameter :: STATUS_PRINT_H = -2 !< Print help status.
integer(I4P), parameter :: STATUS_PRINT_M = -3 !< Print help status to Markdown file.

! errors codes
integer(I4P), parameter :: ERROR_CONSISTENCY = 100 !< CLAs group consistency error.
Expand Down Expand Up @@ -393,6 +396,8 @@ subroutine parse(self, args, ignore_unknown_clas, pref, error_unknown_clas)
endif
elseif (self%cla(a)%act==action_print_help) then
self%error = STATUS_PRINT_H
elseif (self%cla(a)%act==action_print_mark) then
self%error = STATUS_PRINT_M
elseif (self%cla(a)%act==action_print_vers) then
self%error = STATUS_PRINT_V
endif
Expand Down
17 changes: 15 additions & 2 deletions src/lib/flap_command_line_interface_t.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module flap_command_line_interface_t

use face, only : colorize
use flap_command_line_argument_t, only : command_line_argument, ACTION_STORE, ERROR_UNKNOWN
use flap_command_line_arguments_group_t, only : command_line_arguments_group, STATUS_PRINT_H, STATUS_PRINT_V
use flap_command_line_arguments_group_t, only : command_line_arguments_group, STATUS_PRINT_H, STATUS_PRINT_M, STATUS_PRINT_V
use flap_object_t, only : object
use flap_utils_m
use penf
Expand Down Expand Up @@ -453,7 +453,7 @@ subroutine parse(self, pref, args, error)
if (present(error)) error = 0
if (self%is_parsed_) return

! add help and version switches if not done by user
! add help, markdown and version switches if not done by user
if (.not.self%disable_hv) then
do g=0,size(self%clasg,dim=1)-1
if (.not.(self%is_defined(group=self%clasg(g)%group, switch='--help').and.&
Expand All @@ -466,6 +466,16 @@ subroutine parse(self, pref, args, error)
required = .false., &
def = '', &
act = 'print_help')
if (.not.(self%is_defined(group=self%clasg(g)%group, switch='--markdown').and.&
self%is_defined(group=self%clasg(g)%group, switch='-md'))) &
call self%add(pref = pref, &
group_index = g, &
switch = '--markdown', &
switch_ab = '-md', &
help = 'Save this help message in a Markdown file', &
required = .false., &
def = '', &
act = 'print_markdown')
if (.not.(self%is_defined(group=self%clasg(g)%group, switch='--version').and. &
self%is_defined(group=self%clasg(g)%group, switch='-v'))) &
call self%add(pref = pref, &
Expand Down Expand Up @@ -549,6 +559,9 @@ subroutine parse(self, pref, args, error)
stop
endif
enddo
elseif (self%error == STATUS_PRINT_M) then
call self%save_usage_to_markdown(trim(self%progname)//'.md')
stop
endif

! check if all required CLAs have been passed
Expand Down

0 comments on commit 84e0100

Please sign in to comment.