command_line_arguments_group Derived Type

type, public, extends(object) :: command_line_arguments_group

Command Line Arguments Group (CLAsG) class.

CLAsG are useful for building nested commands.


Inherits

type~~command_line_arguments_group~~InheritsGraph type~command_line_arguments_group command_line_arguments_group type~command_line_argument command_line_argument type~command_line_arguments_group->type~command_line_argument cla type~object object type~command_line_arguments_group->type~object type~command_line_argument->type~object

Inherited by

type~~command_line_arguments_group~~InheritedByGraph type~command_line_arguments_group command_line_arguments_group type~command_line_interface command_line_interface type~command_line_interface->type~command_line_arguments_group clasg

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: progname

Program name.

character(len=:), public, allocatable :: version

Program version.

character(len=:), public, allocatable :: help

Help message.

character(len=:), public, allocatable :: help_color

ANSI color of help messages.

character(len=:), public, allocatable :: help_style

ANSI style of help messages.

character(len=:), public, allocatable :: help_markdown

Longer help message, markdown formatted.

character(len=:), public, allocatable :: description

Detailed description.

character(len=:), public, allocatable :: license

License description.

character(len=:), public, allocatable :: authors

Authors list.

character(len=:), public, allocatable :: epilog

Epilogue message.

character(len=:), public, allocatable :: m_exclude

Mutually exclude other CLA(s group).

character(len=:), public, allocatable :: error_message

Meaningful error message to standard-error.

character(len=:), public, allocatable :: error_color

ANSI color of error messages.

character(len=:), public, allocatable :: error_style

ANSI style of error messages.

character(len=512), public, allocatable :: examples(:)

Examples of correct usage.

integer(kind=I4P), public :: error = 0_I4P

Error trapping flag.

integer(kind=I4P), public :: usage_lun = stderr

Output unit to print help/usage messages

integer(kind=I4P), public :: version_lun = stdout

Output unit to print version message

integer(kind=I4P), public :: error_lun = stderr

Error unit to print error messages

character(len=:), public, allocatable :: group

Group name (command).

integer(kind=I4P), public :: Na = 0_I4P

Number of CLA.

integer(kind=I4P), private :: Na_required = 0_I4P

Number of required command line arguments.

integer(kind=I4P), private :: Na_optional = 0_I4P

Number of optional command line arguments.

type(command_line_argument), public, allocatable :: cla(:)

CLA list [1:Na].

logical, public :: is_called = .false.

Flag for checking if CLAs group has been passed to CLI.


Finalization Procedures

final :: finalize

Free dynamic memory when finalizing.

  • private elemental subroutine finalize(self)

    Free dynamic memory when finalizing.

    Arguments

    Type IntentOptional Attributes Name
    type(command_line_arguments_group), intent(inout) :: self

    CLAsG data.


Type-Bound Procedures

procedure, public, pass(self) :: free_object

Free dynamic memory.

  • private elemental subroutine free_object(self)

    Free dynamic memory.

    Arguments

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

    Object data.

procedure, public, pass(self) :: print_version

Print version.

  • private subroutine print_version(self, pref)

    Print version.

    Arguments

    Type IntentOptional Attributes Name
    class(object), intent(in) :: self

    Object data.

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

    Prefixing string.

procedure, public, pass(self) :: print_error_message

Print meaningful error message.

  • private subroutine print_error_message(self)

    Print meaningful error message to standard-error.

    Arguments

    Type IntentOptional Attributes Name
    class(object), intent(in) :: self

    Object data.

procedure, public, pass(self) :: set_examples

Set examples of correct usage.

  • private subroutine set_examples(self, examples)

    Set examples of correct usage.

    Arguments

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

    Object data.

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

    Examples of correct usage.

procedure, public, pass(lhs ) :: assign_object

Assignment overloading.

  • private elemental subroutine assign_object(lhs, rhs)

    Assign two abstract objects.

    Arguments

    Type IntentOptional Attributes Name
    class(object), intent(inout) :: lhs

    Left hand side.

    class(object), intent(in) :: rhs

    Rigth hand side.

procedure, public :: free

Free dynamic memory.

  • private elemental subroutine free(self)

    Free dynamic memory.

    Arguments

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

    CLAsG data.

procedure, public :: check

Check data consistency.

  • private subroutine check(self, pref)

    Check data consistency.

    Arguments

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

    CLAsG data.

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

    Prefixing string.

procedure, public :: is_required_passed

Check if required CLAs are passed.

  • private subroutine is_required_passed(self, pref)

    Check if required CLAs are passed.

    Arguments

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

    CLAsG data.

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

    Prefixing string.

procedure, public :: is_passed

Check if a CLA has been passed.

  • private pure function is_passed(self, switch, position)

    Check if a CLA has been passed.

    Arguments

    Type IntentOptional Attributes Name
    class(command_line_arguments_group), intent(in) :: self

    CLAsG data.

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

    Switch name.

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

    Position of positional CLA.

    Return Value logical

    Check if a CLA has been passed.

procedure, public :: is_defined

Check if a CLA has been defined.

  • private function is_defined(self, switch, pos)

    Check if a CLA has been defined.

    Arguments

    Type IntentOptional Attributes Name
    class(command_line_arguments_group), intent(in) :: self

    CLAsG data.

    character(len=*), intent(in) :: switch

    Switch name.

    integer(kind=I4P), intent(out), optional :: pos

    CLA position.

    Return Value logical

    Check if a CLA has been defined.

procedure, public :: raise_error_m_exclude

Raise error mutually exclusive CLAs passed.

  • private subroutine raise_error_m_exclude(self, pref)

    Raise error mutually exclusive CLAs passed.

    Arguments

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

    CLA data.

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

    Prefixing string.

procedure, public :: add

Add CLA to CLAsG.

procedure, public :: parse

Parse CLAsG arguments.

  • private subroutine parse(self, args, ignore_unknown_clas, pref, error_unknown_clas)

    Parse CLAsG arguments.

    Arguments

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

    CLAsG data.

    character(len=*), intent(in) :: args(:)

    Command line arguments.

    logical, intent(in) :: ignore_unknown_clas

    Disable errors-raising for passed unknown CLAs.

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

    Prefixing string.

    integer(kind=I4P), intent(out) :: error_unknown_clas

    Error flag for passed unknown CLAs.

procedure, public :: usage

Get correct CLAsG usage.

  • private function usage(self, pref, no_header, markdown)

    Get correct CLAsG usage.

    Arguments

    Type IntentOptional Attributes Name
    class(command_line_arguments_group), intent(in) :: self

    CLAsG data.

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

    Prefixing string.

    logical, intent(in), optional :: no_header

    Avoid insert header to usage.

    logical, intent(in), optional :: markdown

    Format things form markdown.

    Return Value character(len=:), allocatable

    Usage string.

procedure, public :: signature

Get CLAsG signature.

  • private function signature(self, bash_completion, plain)

    Get CLAsG signature.

    Arguments

    Type IntentOptional Attributes Name
    class(command_line_arguments_group), intent(in) :: self

    CLAsG data.

    logical, intent(in), optional :: bash_completion

    Return the signature for bash completion.

    logical, intent(in), optional :: plain

    Return the signature as plain switches list.

    Return Value character(len=:), allocatable

    Signature.

procedure, public :: sanitize_defaults

Sanitize default values.

procedure, private :: errored

Trig error occurrence and print meaningful message.

  • private subroutine errored(self, error, pref, a1, a2)

    Trig error occurrence and print meaningful message.

    Arguments

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

    CLAsG data.

    integer(kind=I4P), intent(in) :: error

    Error occurred.

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

    Prefixing string.

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

    First index CLAs group inconsistent.

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

    Second index CLAs group inconsistent.

procedure, private :: check_m_exclusive

Check if two mutually exclusive CLAs have been passed.

  • private subroutine check_m_exclusive(self, pref)

    Check if two mutually exclusive CLAs have been passed.

    Arguments

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

    CLAsG data.

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

    Prefixing string.

procedure, private :: clasg_assign_clasg

Assignment operator.

generic, private :: assignment(=) => clasg_assign_clasg

Assignment operator overloading.

Source Code

type, extends(object) :: command_line_arguments_group
  !< Command Line Arguments Group (CLAsG) class.
  !<
  !< CLAsG are useful for building nested commands.
  private
  character(len=:), allocatable,            public :: group             !< Group name (command).
  integer(I4P),                             public :: Na=0_I4P          !< Number of CLA.
  integer(I4P)                                     :: Na_required=0_I4P !< Number of required command line arguments.
  integer(I4P)                                     :: Na_optional=0_I4P !< Number of optional command line arguments.
  type(command_line_argument), allocatable, public :: cla(:)            !< CLA list [1:Na].
  logical,                                  public :: is_called=.false. !< Flag for checking if CLAs group has been passed to CLI.
  contains
    ! public methods
    procedure, public :: free                  !< Free dynamic memory.
    procedure, public :: check                 !< Check data consistency.
    procedure, public :: is_required_passed    !< Check if required CLAs are passed.
    procedure, public :: is_passed             !< Check if a CLA has been passed.
    procedure, public :: is_defined            !< Check if a CLA has been defined.
    procedure, public :: raise_error_m_exclude !< Raise error mutually exclusive CLAs passed.
    procedure, public :: add                   !< Add CLA to CLAsG.
    procedure, public :: parse                 !< Parse CLAsG arguments.
    procedure, public :: usage                 !< Get correct CLAsG usage.
    procedure, public :: signature             !< Get CLAsG signature.
    procedure, public :: sanitize_defaults     !< Sanitize default values.
    ! private methods
    procedure, private :: errored                             !< Trig error occurrence and print meaningful message.
    procedure, private :: check_m_exclusive                   !< Check if two mutually exclusive CLAs have been passed.
    procedure, private :: clasg_assign_clasg                  !< Assignment operator.
    generic,   private :: assignment(=) => clasg_assign_clasg !< Assignment operator overloading.
    final              :: finalize                            !< Free dynamic memory when finalizing.
endtype command_line_arguments_group