mint.commandlineparser - Palamecia/mint GitHub Wiki
Module
load mint.commandlineparser
This module provides tools to parse the script's command line arguments.
Enums
CommandLineParser.Action
This enum describe the action to apply to a target variable to treat an argument.
Constant | Value | Description |
---|---|---|
Call | 1 |
Uses the call operator of the target variable with the value as parameter. |
Count | 3 |
Calls the ++ operator of the target variable any time the parameter is found. |
Flag | 2 |
Sets the value of the target variable to true . |
Store | 0 |
Stores the value to the target variable. |
CommandLineParser.Argument.Type
This enum describe an argument type.
Constant | Value | Description |
---|---|---|
Option | 0 |
The argument is an option. |
Positionnal | 1 |
The argument is positionnal. |
Classes
CommandLineParser
This class provides a way to parse the script's command line parameters from a simple description of the expected arguments. It can also generate an help message from the description.
Public members
Modifiers | Member | Description |
---|---|---|
enum |
Action | This enum describe the action to apply to a target variable to treat an argum... |
const |
addArgument | Adds an option argument to look for while parsing. The name parameter must ... |
const |
addPositionnalArgument | Adds a positionnal argument to look for while parsing. The name parameter m... |
const |
getScript | Returns the current script's path as an instance of System.File. This method ... |
const |
new | Creates a new parser. |
onError | Prints the error_message on the error output and exit the program with erro... |
|
const |
parse | Parses the command line arguments given by args . The args parameter must ... |
const |
setDescription | Sets the script's description to description . If provided, the --help arg... |
const |
setVersion | Sets the script's version to version . If provided, the --version argument... |
const |
showHelp | Prints the help message on the printer described by printer . |
const |
showVersion | Prints the version message on the printer described by printer . |
Protected members
Modifiers | Member | Description |
---|---|---|
const |
addInternalArgument | Adds a builtin option argument to look for while parsing. The name paramete... |
Private members
Modifiers | Member | Description |
---|---|---|
class |
Argument | This class describe an argument. |
final |
arguments | Internal arguments list. |
final |
description | Internal description value. |
final |
internalArguments | Internal builtin arguments list. |
final |
options | Internal options access. |
final |
positionnalArguments | Internal positionnal arguments list. |
final |
script | Internal script file. |
final |
version | Internal version value. |
CommandLineParser.Argument
This class describe an argument.
Public members
Modifiers | Member | Description |
---|---|---|
enum |
Type | This enum describe an argument type. |
const |
getAction | Returns the action to apply to the target variable for this argument. |
const |
getDescription | Returns the description message for this argument. |
const |
getHelp | Returns the help message for this argument. |
const |
getParameter | Returns the parameter list for this argument. |
const |
getTarget | Returns the target variable for this argument. |
name | Argument name(s). | |
options | Argument options | |
const |
set | Sets the value of the argument. Provided values are given as extra arguments. |
type | Argument type. |
Descriptions
CommandLineParser.Action.Call
1
Uses the call operator of the target variable with the value as parameter.
CommandLineParser.Action.Count
3
Calls the ++
operator of the target variable any time the parameter is found.
CommandLineParser.Action.Flag
2
Sets the value of the target variable to true
.
CommandLineParser.Action.Store
0
Stores the value to the target variable.
CommandLineParser.Argument.Type.Option
0
The argument is an option.
CommandLineParser.Argument.Type.Positionnal
1
The argument is positionnal.
CommandLineParser.Argument.getAction
def (const self)
Returns the action to apply to the target variable for this argument.
CommandLineParser.Argument.getDescription
def (const self)
Returns the description message for this argument.
CommandLineParser.Argument.getHelp
def (const self)
Returns the help message for this argument.
CommandLineParser.Argument.getParameter
def (const self)
Returns the parameter list for this argument.
CommandLineParser.Argument.getTarget
def (const self)
Returns the target variable for this argument.
CommandLineParser.Argument.name
none
Argument name(s).
CommandLineParser.Argument.options
{}
Argument options
CommandLineParser.Argument.set
def (self, ...)
Sets the value of the argument. Provided values are given as extra arguments.
CommandLineParser.Argument.type
none
Argument type.
CommandLineParser.addArgument
def (self, name, options)
Adds an option argument to look for while parsing.
The name
parameter must be a string containing the name expected by the
script in the command line parameter for the given argument. It can also
be an array of string if several names can be used for this argument (i.e.
arguments with a short and long name).
The options
parameter must be an hash containing the following values:
- description (default:
''
): Provides the description used by the help message for this argument. - target (default:
none
): Provides the target variable for this argument. - action (default: depend on target type): Provides the CommandLineParser.Action to apply to the target variable for this argument.
- parameter (default:
[]
): Provides the parameter list for this argument as an array of string.
CommandLineParser.addInternalArgument
def (self, name, options)
Adds a builtin option argument to look for while parsing.
The name
parameter must be a string containing the name expected by the
script in the command line parameter for the given argument. It can also
be an array of string if several names can be used for this argument (i.e.
arguments with a short and long name).
The options
parameter must be an hash containing the following values:
- description (default:
''
): Provides the description used by the help message for this argument. - target (default:
none
): Provides the target variable for this argument. - action (default: depend on target type): Provides the CommandLineParser.Action to apply to the target variable for this argument.
- parameter (default:
[]
): Provides the parameter list for this argument as an array of string.
CommandLineParser.addPositionnalArgument
def (self, name, options)
Adds a positionnal argument to look for while parsing.
The name
parameter must be a string containing the name of the given
argument.
The options
parameter must be an hash containing the following values:
- description (default:
''
): Provides the description used by the help message for this argument. - target (default:
none
): Provides the target variable for this argument. - action (default: depend on target type): Provides the CommandLineParser.Action to apply to the target variable for this argument.
CommandLineParser.arguments
[]
Internal arguments list.
CommandLineParser.description
none
Internal description value.
CommandLineParser.getScript
def (const self)
Returns the current script's path as an instance of System.File. This method must be called after parse in order to be initialized.
CommandLineParser.internalArguments
[]
Internal builtin arguments list.
CommandLineParser.new
def (self)
Creates a new parser.
CommandLineParser.onError
def (const self, error_message)
Prints the error_message
on the error output and exit the program with
error code ExitStatus.Failure.
CommandLineParser.options
{}
Internal options access.
CommandLineParser.parse
def (const self, args)
Parses the command line arguments given by args
. The args
parameter
must be the va_args
variable of the main module or an iterator
containing the same values.
On invalid argument, the onError method is called.
CommandLineParser.positionnalArguments
[]
Internal positionnal arguments list.
CommandLineParser.script
null
Internal script file.
CommandLineParser.setDescription
def (self, description)
Sets the script's description to description
. If provided, the --help
argument will include this description.
CommandLineParser.setVersion
def (self, version)
Sets the script's version to version
. If provided, the --version
argument is enabled.
CommandLineParser.showHelp
def (self, printer = System.stdout)
Prints the help message on the printer described by printer
.
CommandLineParser.showVersion
def (self, printer = System.stdout)
Prints the version message on the printer described by printer
.
CommandLineParser.version
none
Internal version value.