LibCapy - argParser

CLI arguments parser class.

Macros:

Helper macro to automatically deduce the number of argument in the definition list

Helper macro to automatically deduce the number of argument in the definition list (silent version for unit tests)

Helper macro to automatically deduce the number of argument in the definition list

Helper macro to automatically deduce the number of argument in the definition list (silent version for unit tests)

Enumerations:

Enumeration of the possible number of values for one argument in the definition list

Typedefs:

None.

Struct CapyArg :

Struct CapyArg's properties:

The label of the argument (e.g. '--argument')

The short label of the argument (e.g. '-a')

The number or values following this argument

The description of this argument

The list of values of this argument

Struct CapyArg's methods:

None.

Struct CapyArgParser :

Struct CapyArgParser's properties:

The arguments definition

The number of arguments in the definition

The argc and argv argument of the main() function

Silent flag (default: false)

The orphan values (values in argv not associated to an argument in the arguments definition)

Struct CapyArgParser's methods:

Destructor

Print the help message describing the argument definition of the parser

Get the number of values for a given argument (number given via the command line, not the number in the definition)

Input argument(s):

arg: the argument, must be in the argument definitions, may be the label or the shortcut

Output and side effect(s):

Return the number of values

Check if an optional argument is used

Input argument(s):

arg: the argument to check, must be in the argument definitions, may be the label or the shortcut

Output and side effect(s):

Return true if the argument is used, else false

Get a value decoded as int for an optional argument

Input argument(s):

arg: the argument to check, must be in the argument definitions, may be the label or the shortcut
iVal: the index of the value

Output and side effect(s):

Return the requested value, or 0 if the value was missing

Get a value decoded as double for an optional argument

Input argument(s):

arg: the argument to check, must be in the argument definitions, may be the label or the shortcut
iVal: the index of the value

Output and side effect(s):

Return the requested value, or 0.0 if the value was missing

Get a value as a string for an optional argument

Input argument(s):

arg: the argument to check, must be in the argument definitions, may be the label or the shortcut
iVal: the index of the value

Output and side effect(s):

Return the requested value, or NULL if the value was missing

Functions:

Create a CapyArgParser, check the argument definitions and parse the arguments from the command line.

Input argument(s):

argc: the argc argument of the main() function
argv: the argv argument of the main() function
args: the argument definition list
nbArgs: the number of arguments in the definition list
silent: silent flag

Output and side effect(s):

Return a CapyArgParser Exceptions: May raise CapyExc_InvalidCLIArg, CapyExc_MallocFailed

Allocate memory for a CapyArgParser, create it, check the argument definitions and parse the arguments from the command line.

Input argument(s):

argc: the argc argument of the main() function
argv: the argv argument of the main() function
args: the argument definition list
nbArgs: the number of arguments in the definition list
silent: silent flag

Output and side effect(s):

Return a CapyArgParser Exceptions: May raise CapyExc_InvalidCLIArg, CapyExc_MallocFailed

Free the memory used by a CapyArgParser and reset '*that' to NULL

Input argument(s):

that: a pointer to the CapyArgParser to free

2021-10-24
in LibCapy,
61 views
Copyright 2021-2024 Baillehache Pascal