command_line_interface Derived Type

type, public, extends(object) :: command_line_interface

Command Line Interface (CLI) class.


Inherits

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

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

type(command_line_arguments_group), private, allocatable :: clasg(:)

CLA list [1:Na].

character(len=512), private, allocatable :: args(:)

Actually passed command line arguments.

logical, private :: disable_hv = .false.

Disable automatic ‘help’ and ‘version’ CLAs.

logical, private :: is_parsed_ = .false.

Parse status.

logical, private :: ignore_unknown_clas = .false.

Disable errors-raising for passed unknown CLAs.

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

Error trapping flag for unknown CLAs.


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_interface), intent(inout) :: self

    CLI 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_interface), intent(inout) :: self

    CLI data.

procedure, public :: init

Initialize CLI.

  • 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.

    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.

procedure, public :: add_group

Add CLAs group CLI.

  • private subroutine add_group(self, help, description, exclude, examples, group)

    Add CLAs group to CLI.

    Arguments

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

    CLI data.

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

    Help message.

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

    Detailed description.

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

    Group name of the mutually exclusive group.

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

    Examples of correct usage of the group.

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

    Name of the grouped CLAs.

procedure, public :: add

Add CLA to CLI.

  • private subroutine add(self, pref, group, group_index, switch, switch_ab, help, help_markdown, help_color, help_style, required, val_required, positional, position, hidden, act, def, nargs, choices, exclude, envvar, error)

    Add CLA to CLI.

    Read more…

    Arguments

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

    CLI data.

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

    Prefixing string.

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

    Name of the grouped CLAs.

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

    Index of the grouped CLAs.

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

    Switch name.

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

    Abbreviated switch name.

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

    Help message describing the CLA.

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

    Longer help message, markdown formatted.

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

    ANSI color of help messages.

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

    ANSI style of help messages.

    logical, intent(in), optional :: required

    Flag for set required argument.

    logical, intent(in), optional :: val_required

    Flag for set value required for optional argument.

    logical, intent(in), optional :: positional

    Flag for checking if CLA is a positional or a named CLA.

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

    Position of positional CLA.

    logical, intent(in), optional :: hidden

    Flag for hiding CLA, thus it does not compare into help.

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

    CLA value action.

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

    Default value.

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

    Number of arguments consumed by CLA.

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

    List of allowable values for the argument.

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

    Switch name of the mutually exclusive CLA.

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

    Environment variable from which take value.

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

    Error trapping flag.

procedure, public :: is_passed

Check if a CLA has been passed.

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

    Check if a CLA has been passed.

    Arguments

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

    CLI data.

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

    Name of group (command) of CLA.

    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_group

Check if a CLAs group has been defined.

  • private function is_defined_group(self, group, g) result(defined)

    Check if a CLAs group has been defined.

    Arguments

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

    CLI data.

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

    Name of group (command) of CLAs.

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

    Index of group.

    Return Value logical

    Check if a CLAs group has been defined.

procedure, public :: is_defined

Check if a CLA has been defined.

  • private function is_defined(self, switch, group)

    Check if a CLA has been defined.

    Arguments

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

    CLI data.

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

    Switch name.

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

    Name of group (command) of CLAs.

    Return Value logical

    Check if a CLA has been defined.

procedure, public :: is_parsed

Check if CLI has been parsed.

  • private elemental function is_parsed(self)

    Check if CLI has been parsed.

    Arguments

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

    CLI data.

    Return Value logical

    Parsed status.

procedure, public :: set_mutually_exclusive_groups

Set two CLAs group as mutually exclusive.

  • private subroutine set_mutually_exclusive_groups(self, group1, group2)

    Set two CLAs group ad mutually exclusive.

    Arguments

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

    CLI data.

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

    Name of the first grouped CLAs.

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

    Name of the second grouped CLAs.

procedure, public :: run_command => is_called_group

Check if a CLAs group has been run.

  • private function is_called_group(self, group) result(called)

    Check if a CLAs group has been run.

    Arguments

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

    CLI data.

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

    Name of group (command) of CLAs.

    Return Value logical

    Check if a CLAs group has been runned.

procedure, public :: parse

Parse Command Line Interfaces.

  • private subroutine parse(self, pref, args, error)

    Parse Command Line Interfaces by means of a previously initialized CLAs groups list.

    Read more…

    Arguments

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

    CLI data.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Error trapping flag.

generic, public :: get => get_cla, get_cla_list

Get CLA value(s) from CLAs list parsed.

  • private subroutine get_cla(self, val, pref, args, group, switch, position, error)

    Get CLA (single) value from CLAs list parsed.

    Read more…

    Arguments

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

    CLI data.

    class(*), intent(inout) :: val

    CLA value.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed.

    Read more…

    Arguments

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

    CLI data.

    class(*), intent(inout) :: val(1:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

Get CLA value(s) from CLAs list parsed, varying size list.

  • private subroutine get_cla_list_varying_R8P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, real(R8P).

    Read more…

    Arguments

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

    CLI data.

    real(kind=R8P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_R4P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, real(R4P).

    Read more…

    Arguments

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

    CLI data.

    real(kind=R4P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_I8P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I8P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I8P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_I4P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I4P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I4P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_I2P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I2P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I2P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_I1P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I1P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I1P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_logical(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, logical.

    Read more…

    Arguments

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

    CLI data.

    logical, intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

  • private subroutine get_cla_list_varying_char(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, character.

    Read more…

    Arguments

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

    CLI data.

    character(len=*), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, public :: usage

Get CLI usage.

  • private function usage(self, g, pref, no_header, no_examples, no_epilog, markdown) result(usaged)

    Print correct usage of CLI.

    Arguments

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

    CLI data.

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

    Group index.

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

    Prefixing string.

    logical, intent(in), optional :: no_header

    Avoid insert header to usage.

    logical, intent(in), optional :: no_examples

    Avoid insert examples to usage.

    logical, intent(in), optional :: no_epilog

    Avoid insert epilogue to usage.

    logical, intent(in), optional :: markdown

    Format things with markdown

    Return Value character(len=:), allocatable

    Usage string.

procedure, public :: signature

Get CLI signature.

  • private function signature(self, bash_completion)

    Get signature.

    Arguments

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

    CLI data.

    logical, intent(in), optional :: bash_completion

    Return the signature for bash completion.

    Return Value character(len=:), allocatable

    Signature.

procedure, public :: print_usage

Print correct usage of CLI.

  • private subroutine print_usage(self, pref)

    Print correct usage.

    Arguments

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

    CLI data.

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

    Prefixing string.

procedure, public :: save_bash_completion

Save bash completion script (for named CLAs only).

  • private subroutine save_bash_completion(self, bash_file, error)

    Save bash completion script (for named CLAs only).

    Arguments

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

    CLI data.

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

    Output file name of bash completion script.

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

    Error trapping flag.

procedure, public :: save_man_page

Save CLI usage as man page.

  • private subroutine save_man_page(self, man_file, error)

    Save CLI usage as man page.

    Arguments

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

    CLI data.

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

    Output file name for saving man page.

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

    Error trapping flag.

procedure, public :: save_usage_to_markdown

Save CLI usage as markdown.

  • private subroutine save_usage_to_markdown(self, markdown_file, error)

    Save CLI usage as markdown.

    Arguments

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

    CLI data.

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

    Output file name for saving man page.

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

    Error trapping flag.

procedure, private :: errored

Trig error occurence and print meaningful message.

  • private subroutine errored(self, error, pref, group, switch)

    Trig error occurrence and print meaningful message.

    Arguments

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

    Object data.

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

    Error occurred.

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

    Prefixing string.

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

    Group name.

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

    CLA switch name.

procedure, private :: check

Check data consistency.

  • private subroutine check(self, pref, error)

    Check data consistency.

    Arguments

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

    CLI data.

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

    Prefixing string.

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

    Error trapping flag.

procedure, private :: check_m_exclusive

Check if two mutually exclusive CLAs group have been called.

  • private subroutine check_m_exclusive(self, pref)

    Check if two mutually exclusive CLAs group have been called.

    Arguments

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

    CLI data.

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

    Prefixing string.

procedure, private :: get_clasg_indexes

Get CLAs groups indexes.

  • private subroutine get_clasg_indexes(self, ai)

    Get the argument indexes of CLAs groups defined parsing the actual passed CLAs.

    Arguments

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

    CLI data.

    integer(kind=I4P), intent(out), allocatable :: ai(:,:)

    CLAs grouped indexes.

generic, private :: get_args => get_args_from_string, get_args_from_invocation

Get CLAs.

  • private subroutine get_args_from_string(self, args, ai)

    Get CLAs from string.

    Arguments

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

    CLI data.

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

    String containing command line arguments.

    integer(kind=I4P), intent(out), allocatable :: ai(:,:)

    CLAs grouped indexes.

  • private subroutine get_args_from_invocation(self, ai)

    Get CLAs from CLI invocation.

    Arguments

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

    CLI data.

    integer(kind=I4P), intent(out), allocatable :: ai(:,:)

    CLAs grouped indexes.

procedure, private :: get_args_from_string

Get CLAs from string.

  • private subroutine get_args_from_string(self, args, ai)

    Get CLAs from string.

    Arguments

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

    CLI data.

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

    String containing command line arguments.

    integer(kind=I4P), intent(out), allocatable :: ai(:,:)

    CLAs grouped indexes.

procedure, private :: get_args_from_invocation

Get CLAs from CLI invocation.

  • private subroutine get_args_from_invocation(self, ai)

    Get CLAs from CLI invocation.

    Arguments

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

    CLI data.

    integer(kind=I4P), intent(out), allocatable :: ai(:,:)

    CLAs grouped indexes.

procedure, private :: get_cla

Get CLA (single) value from CLAs list parsed.

  • private subroutine get_cla(self, val, pref, args, group, switch, position, error)

    Get CLA (single) value from CLAs list parsed.

    Read more…

    Arguments

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

    CLI data.

    class(*), intent(inout) :: val

    CLA value.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list

Get CLA multiple values from CLAs list parsed.

  • private subroutine get_cla_list(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed.

    Read more…

    Arguments

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

    CLI data.

    class(*), intent(inout) :: val(1:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_R16P

Get CLA multiple values from CLAs list parsed, varying size, R16P.

  • private subroutine get_cla_list_varying_R16P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, real(R16P).

    Read more…

    Arguments

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

    CLI data.

    real(kind=R16P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_R8P

Get CLA multiple values from CLAs list parsed, varying size, R8P.

  • private subroutine get_cla_list_varying_R8P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, real(R8P).

    Read more…

    Arguments

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

    CLI data.

    real(kind=R8P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_R4P

Get CLA multiple values from CLAs list parsed, varying size, R4P.

  • private subroutine get_cla_list_varying_R4P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, real(R4P).

    Read more…

    Arguments

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

    CLI data.

    real(kind=R4P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_I8P

Get CLA multiple values from CLAs list parsed, varying size, I8P.

  • private subroutine get_cla_list_varying_I8P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I8P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I8P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_I4P

Get CLA multiple values from CLAs list parsed, varying size, I4P.

  • private subroutine get_cla_list_varying_I4P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I4P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I4P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_I2P

Get CLA multiple values from CLAs list parsed, varying size, I2P.

  • private subroutine get_cla_list_varying_I2P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I2P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I2P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_I1P

Get CLA multiple values from CLAs list parsed, varying size, I1P.

  • private subroutine get_cla_list_varying_I1P(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, integer(I1P).

    Read more…

    Arguments

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

    CLI data.

    integer(kind=I1P), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_logical

Get CLA multiple values from CLAs list parsed, varying size, bool.

  • private subroutine get_cla_list_varying_logical(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, logical.

    Read more…

    Arguments

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

    CLI data.

    logical, intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: get_cla_list_varying_char

Get CLA multiple values from CLAs list parsed, varying size, char.

  • private subroutine get_cla_list_varying_char(self, val, pref, args, group, switch, position, error)

    Get CLA multiple values from CLAs list parsed with varying size list, character.

    Read more…

    Arguments

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

    CLI data.

    character(len=*), intent(out), allocatable :: val(:)

    CLA values.

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

    Prefixing string.

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

    String containing command line arguments.

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

    Name of group (command) of CLA.

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

    Switch name.

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

    Position of positional CLA.

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

    Error trapping flag.

procedure, private :: cli_assign_cli

CLI assignment overloading.

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

CLI assignment overloading.

Source Code

type, extends(object), public :: command_line_interface
  !< Command Line Interface (CLI) class.
  private
  type(command_line_arguments_group), allocatable :: clasg(:)                    !< CLA list [1:Na].
#ifdef __GFORTRAN__
  character(512  ), allocatable                   :: args(:)                     !< Actually passed command line arguments.
#else
  character(len=:), allocatable                   :: args(:)                     !< Actually passed command line arguments.
#endif
  logical                                         :: disable_hv=.false.          !< Disable automatic 'help' and 'version' CLAs.
  logical                                         :: is_parsed_=.false.          !< Parse status.
  logical                                         :: ignore_unknown_clas=.false. !< Disable errors-raising for passed unknown CLAs.
  integer(I4P)                                    :: error_unknown_clas=0_I4P    !< Error trapping flag for unknown CLAs.
  contains
    ! public methods
    procedure, public :: free                            !< Free dynamic memory.
    procedure, public :: init                            !< Initialize CLI.
    procedure, public :: add_group                       !< Add CLAs group CLI.
    procedure, public :: add                             !< Add CLA to CLI.
    procedure, public :: is_passed                       !< Check if a CLA has been passed.
    procedure, public :: is_defined_group                !< Check if a CLAs group has been defined.
    procedure, public :: is_defined                      !< Check if a CLA has been defined.
    procedure, public :: is_parsed                       !< Check if CLI has been parsed.
    procedure, public :: set_mutually_exclusive_groups   !< Set two CLAs group as mutually exclusive.
    procedure, public :: run_command => is_called_group  !< Check if a CLAs group has been run.
    procedure, public :: parse                           !< Parse Command Line Interfaces.
    generic,   public :: get =>   &
                         get_cla, &
                         get_cla_list                    !< Get CLA value(s) from CLAs list parsed.
    generic,   public :: get_varying =>                &
#if defined _R16P
                         get_cla_list_varying_R16P,    &
#endif
                         get_cla_list_varying_R8P,     &
                         get_cla_list_varying_R4P,     &
                         get_cla_list_varying_I8P,     &
                         get_cla_list_varying_I4P,     &
                         get_cla_list_varying_I2P,     &
                         get_cla_list_varying_I1P,     &
                         get_cla_list_varying_logical, &
                         get_cla_list_varying_char       !< Get CLA value(s) from CLAs list parsed, varying size list.
    procedure, public :: usage                           !< Get CLI usage.
    procedure, public :: signature                       !< Get CLI signature.
    procedure, public :: print_usage                     !< Print correct usage of CLI.
    procedure, public :: save_bash_completion            !< Save bash completion script (for named CLAs only).
    procedure, public :: save_man_page                   !< Save CLI usage as man page.
    procedure, public :: save_usage_to_markdown          !< Save CLI usage as markdown.
    ! private methods
    procedure, private :: errored                         !< Trig error occurence and print meaningful message.
    procedure, private :: check                           !< Check data consistency.
    procedure, private :: check_m_exclusive               !< Check if two mutually exclusive CLAs group have been called.
    procedure, private :: get_clasg_indexes               !< Get CLAs groups indexes.
    generic,   private :: get_args =>           &
                          get_args_from_string, &
                          get_args_from_invocation        !< Get CLAs.
    procedure, private :: get_args_from_string            !< Get CLAs from string.
    procedure, private :: get_args_from_invocation        !< Get CLAs from CLI invocation.
    procedure, private :: get_cla                         !< Get CLA (single) value from CLAs list parsed.
    procedure, private :: get_cla_list                    !< Get CLA multiple values from CLAs list parsed.
    procedure, private :: get_cla_list_varying_R16P       !< Get CLA multiple values from CLAs list parsed, varying size, R16P.
    procedure, private :: get_cla_list_varying_R8P        !< Get CLA multiple values from CLAs list parsed, varying size, R8P.
    procedure, private :: get_cla_list_varying_R4P        !< Get CLA multiple values from CLAs list parsed, varying size, R4P.
    procedure, private :: get_cla_list_varying_I8P        !< Get CLA multiple values from CLAs list parsed, varying size, I8P.
    procedure, private :: get_cla_list_varying_I4P        !< Get CLA multiple values from CLAs list parsed, varying size, I4P.
    procedure, private :: get_cla_list_varying_I2P        !< Get CLA multiple values from CLAs list parsed, varying size, I2P.
    procedure, private :: get_cla_list_varying_I1P        !< Get CLA multiple values from CLAs list parsed, varying size, I1P.
    procedure, private :: get_cla_list_varying_logical    !< Get CLA multiple values from CLAs list parsed, varying size, bool.
    procedure, private :: get_cla_list_varying_char       !< Get CLA multiple values from CLAs list parsed, varying size, char.
    procedure, private :: cli_assign_cli                  !< CLI assignment overloading.
    generic,   private :: assignment(=) => cli_assign_cli !< CLI assignment overloading.
    final              :: finalize                        !< Free dynamic memory when finalizing.
endtype command_line_interface