Bash Argsparse Library WTFPLv2. More...
Functions | |
__argsparse_parse_options_valuecheck (option, value) | |
Check a value given to an option. | |
__argsparse_set_option (option) | |
Resolv option-specific setter function and invoke it. | |
__argsparse_values_array_identifier (option) | |
Prints the name of the array containing all user-declared acceptable values for an option. | |
argsparse_allow_no_argument (string) | |
Allow empty command lines to run. | |
argsparse_check_option_type (type, value) | |
Check if a value matches a given type. | |
argsparse_describe_parameters (param...) | |
Describe non-option positionnal parameters. | |
argsparse_get_cumulative_array_name (option) | |
Print the name of the array used for "cumulative" and "cumulativeset" options. | |
argsparse_has_option_property (option, property) | |
Determine if an option has a property. | |
argsparse_is_option_set (option) | |
Return True if an option has been set on the command line. | |
argsparse_maximum_parameters (unsigned_int) | |
Set the maximum number of non-option parameters expected on the command line. | |
argsparse_minimum_parameters (unsigned_int) | |
Set the minimum number of non-option parameters expected on the command line. | |
argsparse_option_description (option) | |
Prints to stdout the description of given option. | |
argsparse_option_to_identifier (option) | |
Give the identifier name associated to an option. | |
argsparse_parse_options (parameters...) | |
Parse program options. | |
argsparse_report (option...) | |
Prints a basic report of all passed options. | |
argsparse_set_alias (option) | |
"alias" property specific option-setting hook. | |
argsparse_set_cumulative_option (option, value) | |
"cumulative" property specific option-setting hook. | |
argsparse_set_cumulativeset_option (option, value) | |
"cumulativeset" property specific option-setting hook. | |
argsparse_set_option (option, value) | |
Default option-setting hook. | |
argsparse_set_option_property (property, option...) | |
Enable a property to a list of options. | |
argsparse_set_option_with_value (option, value) | |
"value" property specific option-setting hook. | |
argsparse_set_option_without_value (option) | |
The option-setting hook for options not accepting values. | |
argsparse_usage () | |
A generic help message generated from the options and their descriptions. | |
argsparse_usage_long () | |
Fully describe and program and its options to the end-user. | |
argsparse_usage_short () | |
Print a short description of the program syntax. | |
argsparse_use_option (optstring, description, property...) | |
Define a new option. | |
set_option_help () | |
Default trigger for --help option. | |
usage () | |
Default usage function. | |
Variables | |
Integer | __argsparse_maximum_parameters = 1000000 |
Internal use only. | |
Integer | __argsparse_minimum_parameters = 0 |
Internal use only. | |
String AssociativeArray | __argsparse_options_default_values |
Internal use only. | |
String AssociativeArray | __argsparse_options_descriptions |
Internal use only. | |
String AssociativeArray | __argsparse_options_properties |
Internal use only. | |
String Array | __argsparse_parameters_description |
Internal use only. | |
String AssociativeArray | __argsparse_short_options |
Internal use only. | |
String AssociativeArray | __argsparse_tmp_identifiers |
Internal use. | |
ReadOnly String | argsparse_pgm |
The name of the program currently using argsparse. | |
String | argsparse_usage_description |
Usage description additionnal string. | |
ReadOnly String | ARGSPARSE_VERSION = 1.7 |
argsparse version number | |
String AssociativeArray | program_options |
Options values. | |
String Array | program_params |
Positionnal parameters of the script. |
Bash Argsparse Library WTFPLv2.
argsparse_use_option "optstring" "option description string" \ [ "property" ... ] [ "optional default value" ]
file directory pipe terminal socket link char unsignedint uint integer int hexa ipv4 ipv6 ip hostname host portnumber port username group date
argsparse_set_option_property "exclude:opt1 opt2" foo
argsparse_use_option opt "my description" "alias:opt1 opt2"
argsparse_use_option opt1 "some description" cumulative
--opt1 value1 --opt1 value2
argsparse_use_option opt1 "some description" cumulativeset
--opt1 value1 --opt1 value2 --opt1 value1
argsparse_use_option opt1 "something" require:"opt2 opt3"
argsparse_has_option_property <option> <property>
argsparse_is_option_set "long-option-name"
__argsparse_parse_options_valuecheck | ( | option | , | |
value | ||||
) |
Check a value given to an option.
If an enumeration has been defined for the option, check against that. If there's no enumeration, but option has a type property, then check against the type. In the end, check against check_value_of_<option> function, if it's been defined.
option | an option name. | |
value | anything. |
0 | if value is correct for given option. |
__argsparse_values_array_identifier | ( | option | ) |
Prints the name of the array containing all user-declared acceptable values for an option.
from "opt" or "opt-name" string, prints "option_opt_values[@]" or "option_opt_name_values[@]", unless array is not declared, in which case function will return an error.
option | an option name. |
1 | if array has not been declared | |
0 | else. Array name will be written to stdout. |
argsparse_allow_no_argument | ( | string | ) |
Allow empty command lines to run.
Change argsparse behaviour for empty command lines. Default says "no argument triggers usage".
string | if (case-insensitive) "yes", "true" or "1", the value is considered as affirmative. Anything else is a negative value. |
0 | unless there's more than one parameter (or none). |
argsparse_check_option_type | ( | type | , | |
value | ||||
) |
Check if a value matches a given type.
Return True if value is of type type.
type | A case-insensitive type name. | |
value | a value to check. |
0 | if the value matches the given type format. |
argsparse_describe_parameters | ( | param... | ) |
Describe non-option positionnal parameters.
param... | a list of label describing positionnal parameters. These labels can have special forms such as:
|
0 |
This function has currently 2 purposes:
argsparse_get_cumulative_array_name | ( | option | ) |
Print the name of the array used for "cumulative" and "cumulativeset" options.
option | an option name. |
For "option-name" usually prints "cumulated_values_option_name".
argsparse_is_option_set | ( | option | ) |
Return True if an option has been set on the command line.
option | an option name. |
0 | if given option has been set on the command line. |
argsparse_option_description | ( | option | ) |
Prints to stdout the description of given option.
option | an option name. |
0 | if given option has been previously declared. |
argsparse_option_to_identifier | ( | option | ) |
Give the identifier name associated to an option.
Transforms and prints an option name into a string which suitable to be part of a function or a variable name.
option | an option name. |
argsparse_parse_options | ( | parameters... | ) |
Parse program options.
This function will make option parsing happen, and if an error is detected, the usage() function will be invoked, if it has been defined. If it's not defined, the function will return 1. Parse options, and return if everything went fine.
parameters... | should be the program arguments. |
0 | if the whole option parsing process went fine. | |
1 | if an error is encoutered and usage does not perform an exit. |
argsparse_report | ( | option... | ) |
Prints a basic report of all passed options.
Kinda useful for a --debug, or a --verbose option, this function will print options and their values.
option... | A list of option name. If omitted all options will be displayed. |
0 |
argsparse_use_option | ( | optstring | , | |
description | , | |||
property... | ||||
) |
Define a new option.
optstring | an optstring. | |
description | the option description, for the usage function. | |
property... | an non-ordered list of keywords. Recognized property keywords are:
|
0 | if no error is encountered. | |
2 | if option name is bad (a message will be printed) | |
3 | if option name conflicts with another option (a message will be printed) | |
4 | if a wrong property name is provided. (a message will be printed) |
ReadOnly String argsparse_pgm |
The name of the program currently using argsparse.
Automatically set by argsparse at load time, it contains the basename (path-less but with extension, if any) of the main script. Used internally to print error messages and by usage-related functions, but can be used by the loading script.
AssociativeArray program_options |
Options values.
After argsparse_parse_options(), it will contain (if no hook is set for "optionname")
Array program_params |
Positionnal parameters of the script.
After argsparse_parse_options(), it will contain all non-option parameters. (Typically, everything found after the '--')