The Bash Argsparse Library
An high level argument parsing library for bash.
|
Bash Argsparse Library
Functions | |
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_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 () | |
"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 () | |
argsparse_usage_short () | |
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 = 100000 |
Internal use only. | |
Integer | __argsparse_minimum_parameters = 0 |
Internal use only. | |
AssociativeArray | __argsparse_options_default_values |
Internal use only. | |
AssociativeArray | __argsparse_options_descriptions |
Internal use only. | |
AssociativeArray | __argsparse_options_properties |
Internal use only. | |
AssociativeArray | __argsparse_short_options |
Internal use only. | |
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.6 |
argsparse version number | |
AssociativeArray | program_options |
Options values. | |
Array | program_params |
Positionnal parameters of the script. |
Bash Argsparse Library
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
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_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. |
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_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. |
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) |
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 '--')