cli_parse Subroutine

private subroutine cli_parse(this, err)

Parse the real command line.

Collects get_command_argument into an array and forwards to parse_args, which holds the whole of the logic.

Type Bound

cli_t

Arguments

Type IntentOptional Attributes Name
class(cli_t), intent(inout) :: this
type(error_t), intent(inout), optional :: err

Set on a parse or validation failure.


Calls

proc~~cli_parse~~CallsGraph proc~cli_parse cli_t%cli_parse proc~cli_parse_args cli_t%cli_parse_args proc~cli_parse->proc~cli_parse_args proc~cli_find cli_t%cli_find proc~cli_parse_args->proc~cli_find proc~cli_find_short cli_find_short proc~cli_parse_args->proc~cli_find_short proc~fail~2 fail proc~cli_parse_args->proc~fail~2 proc~is_long is_long proc~cli_parse_args->proc~is_long proc~is_short is_short proc~cli_parse_args->proc~is_short proc~looks_numeric looks_numeric proc~cli_parse_args->proc~looks_numeric proc~next_positional next_positional proc~cli_parse_args->proc~next_positional proc~error_set error_t%error_set proc~fail~2->proc~error_set

Variables

Type Visibility Attributes Name Initial
integer, private :: arg_index

Bare default integer on purpose, and the one place in this module where that is right: F2018 16.9.82 defines NUMBER, LENGTH and STATUS of get_command_argument as default integer, so these must not follow default_int. Under PIC_DEFAULT_INT8 they would otherwise become int64 and the call would not compile.

integer, private :: arg_len

Bare default integer on purpose, and the one place in this module where that is right: F2018 16.9.82 defines NUMBER, LENGTH and STATUS of get_command_argument as default integer, so these must not follow default_int. Under PIC_DEFAULT_INT8 they would otherwise become int64 and the call would not compile.

type(string_type), private, allocatable :: args(:)
integer(kind=default_int), private :: i
integer(kind=default_int), private :: n

Source Code

   subroutine cli_parse(this, err)
      !! Parse the real command line.
      !!
      !! Collects `get_command_argument` into an array and forwards to
      !! `parse_args`, which holds the whole of the logic.
      class(cli_t), intent(inout) :: this
      type(error_t), intent(inout), optional :: err
         !! Set on a parse or validation failure.

      type(string_type), allocatable :: args(:)
      integer(default_int) :: i, n
      integer :: arg_index, arg_len
         !! Bare default integer on purpose, and the one place in this module
         !! where that is right: F2018 16.9.82 defines NUMBER, LENGTH and
         !! STATUS of `get_command_argument` as default integer, so these must
         !! not follow `default_int`. Under `PIC_DEFAULT_INT8` they would
         !! otherwise become `int64` and the call would not compile.

      n = int(command_argument_count(), default_int)
      allocate (args(n))
      do i = 1_default_int, n
         arg_index = int(i)
         call get_command_argument(arg_index, length=arg_len)
         block
            character(len=arg_len) :: buffer
            call get_command_argument(arg_index, buffer)
            args(i) = buffer
         end block
      end do
      call this%parse_args(args, err)
   end subroutine cli_parse