init Subroutine

private subroutine init(self, progname, version, help, description, license, authors, examples, epilog, disable_hv, usage_lun, error_lun, version_lun, error_color, error_style, ignore_unknown_clas)

Initialize CLI.

Type Bound

command_line_interface

Arguments

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

CLI data.

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

Program name.

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

Program version.

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

Help message introducing the CLI usage.

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

Detailed description message introducing the program.

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

License description.

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

Authors list.

character(len=*), intent(in), optional :: examples(1:)

Examples of correct usage.

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

Epilog message.

logical, intent(in), optional :: disable_hv

Disable automatic insert of ‘help’ and ‘version’ CLAs.

integer(kind=I4P), intent(in), optional :: usage_lun

Unit number to print usage/help.

integer(kind=I4P), intent(in), optional :: error_lun

Unit number to print error info.

integer(kind=I4P), intent(in), optional :: version_lun

Unit number to print version/license info.

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

ANSI color of error messages.

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

ANSI style of error messages.

logical, intent(in), optional :: ignore_unknown_clas

Disable errors-raising for passed unknown CLAs.


Calls

proc~~init~~CallsGraph proc~init flap_command_line_interface_t::command_line_interface%init proc~assign_object flap_object_t::object%assign_object proc~init->proc~assign_object proc~set_examples flap_object_t::object%set_examples proc~init->proc~set_examples

Called by

proc~~init~~CalledByGraph proc~init flap_command_line_interface_t::command_line_interface%init proc~fake_call flap_test_group::fake_call proc~fake_call->proc~init program~flap_save_bash_completion flap_save_bash_completion program~flap_save_bash_completion->proc~init program~flap_save_man_page flap_save_man_page program~flap_save_man_page->proc~init program~flap_save_usage_to_markdown flap_save_usage_to_markdown program~flap_save_usage_to_markdown->proc~init program~flap_test_action_store flap_test_action_store program~flap_test_action_store->proc~init program~flap_test_ansi_color_style flap_test_ansi_color_style program~flap_test_ansi_color_style->proc~init program~flap_test_basic flap_test_basic program~flap_test_basic->proc~init program~flap_test_choices_logical flap_test_choices_logical program~flap_test_choices_logical->proc~init program~flap_test_duplicated_clas flap_test_duplicated_clas program~flap_test_duplicated_clas->proc~init program~flap_test_group_examples flap_test_group_examples program~flap_test_group_examples->proc~init program~flap_test_hidden flap_test_hidden program~flap_test_hidden->proc~init program~flap_test_ignore_unknown_clas flap_test_ignore_unknown_clas program~flap_test_ignore_unknown_clas->proc~init program~flap_test_minimal flap_test_minimal program~flap_test_minimal->proc~init program~flap_test_nargs_insufficient flap_test_nargs_insufficient program~flap_test_nargs_insufficient->proc~init program~flap_test_nargs_insufficient~2 flap_test_nargs_insufficient program~flap_test_nargs_insufficient~2->proc~init program~flap_test_nested flap_test_nested program~flap_test_nested->proc~init program~flap_test_string flap_test_string program~flap_test_string->proc~init program~flap_test_group flap_test_group program~flap_test_group->proc~fake_call

Source Code

  subroutine init(self, progname, version, help, description, license, authors, examples, epilog, disable_hv, &
                  usage_lun, error_lun, version_lun, error_color, error_style, ignore_unknown_clas)
  !< Initialize CLI.
  class(command_line_interface), intent(inout) :: self                !< CLI data.
  character(*), optional,        intent(in)    :: progname            !< Program name.
  character(*), optional,        intent(in)    :: version             !< Program version.
  character(*), optional,        intent(in)    :: help                !< Help message introducing the CLI usage.
  character(*), optional,        intent(in)    :: description         !< Detailed description message introducing the program.
  character(*), optional,        intent(in)    :: license             !< License description.
  character(*), optional,        intent(in)    :: authors             !< Authors list.
  character(*), optional,        intent(in)    :: examples(1:)        !< Examples of correct usage.
  character(*), optional,        intent(in)    :: epilog              !< Epilog message.
  logical,      optional,        intent(in)    :: disable_hv          !< Disable automatic insert of 'help' and 'version' CLAs.
  integer(I4P), optional,        intent(in)    :: usage_lun           !< Unit number to print usage/help.
  integer(I4P), optional,        intent(in)    :: version_lun         !< Unit number to print version/license info.
  integer(I4P), optional,        intent(in)    :: error_lun           !< Unit number to print error info.
  character(*), optional,        intent(in)    :: error_color         !< ANSI color of error messages.
  character(*), optional,        intent(in)    :: error_style         !< ANSI style of error messages.
  logical,      optional,        intent(in)    :: ignore_unknown_clas !< Disable errors-raising for passed unknown CLAs.
  character(len=:), allocatable                :: prog_invocation     !< Complete program invocation.
  integer(I4P)                                 :: invocation_length   !< Length of invocation.
  integer(I4P)                                 :: retrieval_status    !< Retrieval status.

  call self%free
  if (present(progname)) then
    self%progname = progname
  else
    ! try to set the default progname to the 0th command line entry a-la unix $0
    call get_command_argument(0, length=invocation_length)
    allocate(character(len=invocation_length) :: prog_invocation)
    call get_command_argument(0, value=prog_invocation, status=retrieval_status)
    if (retrieval_status==0) then
      self%progname = prog_invocation
    else
      self%progname = 'program'
    endif
  endif
  self%version     = 'unknown' ; if (present(version    )) self%version     = version
  self%help        = 'usage: ' ; if (present(help       )) self%help        = help
  self%description = ''        ; if (present(description)) self%description = description
  self%license     = ''        ; if (present(license    )) self%license     = license
  self%authors     = ''        ; if (present(authors    )) self%authors     = authors
  call self%set_examples(examples)
  self%epilog      = '' ; if (present(epilog     ))         self%epilog              = epilog
                          if (present(disable_hv ))         self%disable_hv          = disable_hv         ! default set by self%free
                          if (present(usage_lun  ))         self%usage_lun           = usage_lun          ! default set by self%free
                          if (present(version_lun))         self%version_lun         = version_lun        ! default set by self%free
                          if (present(error_lun  ))         self%error_lun           = error_lun          ! default set by self%free
  self%error_color = '' ; if (present(error_color))         self%error_color         = error_color
  self%error_style = '' ; if (present(error_style))         self%error_style         = error_style
                          if (present(ignore_unknown_clas)) self%ignore_unknown_clas = ignore_unknown_clas! default set by self%free
  ! initialize only the first default group
  allocate(self%clasg(0:0))
  call self%clasg(0)%assign_object(self)
  self%clasg(0)%group = ''
  endsubroutine init