Skip to content
Stefano Zaghi edited this page Mar 24, 2016 · 3 revisions

get

Signature

call cli%get(val, pref, args, group, switch, position, error)
Meaning

Get (retrieve) CLA (single or list) value(s) from CLAs values previously parsed.

Dummy arguments
class(*),               intent(inout) :: val      !< CLA value.
character(*), optional, intent(in)    :: pref     !< Prefixing string.
character(*), optional, intent(in)    :: args     !< String containing command line arguments.
character(*), optional, intent(in)    :: group    !< Name of group (command) of CLAs.
character(*), optional, intent(in)    :: switch   !< Switch name.
integer(I4P), optional, intent(in)    :: position !< Position of positional CLA.
integer(I4P), optional, intent(out)   :: error    !< Error trapping flag.

Note that for list values (array) CLA the dummy argument val is not a scalar, but an assumed shape array.

Note that the CLA value is retrieved by means of an unlimited polymorphic class, thus the following types are the only presently supported:

  • reals, of any kind;
  • integers, of any kind;
  • strings;
  • logical, of the default kind.

The following rules apply:

  • if cli%parse(...) is not been called before it is automatically called by cli%get: the optional argument args is passed from cli%get to cli%parse;
  • if no group is passed it assumed that the CLA belongs to the default (not named) one (group number 0);
  • if switch name is passed, the eventual position passed is not used; switch is checked with both switch and switch_ab definitions;
  • position must be passed for positional CLA;
  • val can be either a scalar (as above listed) or an array (not listed for the sake of brevity);
  • for optional (not required) CLA, the default value is used if the CLA has not been passed;
  • for environmental CLA, the value is computed by the following steps (in order):
    • check if it is directly passed to the CLI and, in case, use this value;
    • if it is not directly passed to the CLI check if it is defined into the environment (by means of the environment variable name specified by the add method) and, in case, use this value;
    • if it is not directly passed and the evinroment does not defined it, use the eventual default value (specified by the add method).
Usage

Must be used for getting (retrieving) a CLA value

use flap

type(command_line_interface):: cli
character(500)::               commit_message
integer::                      error

call cli%init(...)
call cli%add(...)
call cli%parse(...)

! getting the actual CLAs value
call cli%get(group='commit',&
             switch='-m',   &
             val=commit_message,&
             error=error)
if (error/=0) then
  stop
else
  print "(A)", commit_message
endif

For trapping errors the dummy argument error can be used. The complete errors values are listed in Errors-codes.

Clone this wiki locally