The Bash Argsparse Library 1.8
An high level argument parsing library for bash.
Loading...
Searching...
No Matches
Functions | Variables
argsparse.sh File Reference

Bash Argsparse Library. More...

Functions

 __argsparse_parse_options_valuecheck (option, value)
 Check a value given to an option.
 
 __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_maximum_parameters (unsigned_int)
 
 argsparse_minimum_parameters (unsigned_int)
 
 argsparse_option_to_identifier (option)
 Give the identifier name associated to an option.
 
 argsparse_set_alias (option)
 
 argsparse_set_cumulative_option (option, value)
 
 argsparse_set_cumulativeset_option (option, value)
 
 argsparse_set_option (option, value)
 
 argsparse_set_option_with_value (option, value)
 
 argsparse_set_option_without_value (option)
 
 argsparse_usage ()
 
 argsparse_usage_long ()
 
 argsparse_usage_short ()
 
 set_option_help ()
 
 usage ()
 

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 Array __argsparse_parameters_description
 
ReadOnly String argsparse_pgm
 The name of the program currently using argsparse.
 
String argsparse_usage_description
 
ReadOnly String ARGSPARSE_VERSION = 1.8
 argsparse version number
 

Detailed Description

Bash Argsparse Library.

Author
Damien Nadé bash-.nosp@m.args.nosp@m.parse.nosp@m.@liv.nosp@m.na.or.nosp@m.g
Version
1.8

Function Documentation

◆ __argsparse_parse_options_valuecheck()

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

Parameters
optionan option name.
valueanything.
Return values
0if value is correct for given option.

◆ __argsparse_values_array_identifier()

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

Parameters
optionan option name.
Return values
1if array has not been declared
0else. Array name will be written to stdout.

◆ argsparse_allow_no_argument()

argsparse_allow_no_argument ( string  )

Allow empty command lines to run.

Change argsparse behaviour for empty command lines. Default says "no argument triggers usage".

Parameters
stringif (case-insensitive) "yes", "true" or "1", the value is considered as affirmative. Anything else is a negative value.
Return values
0unless there's more than one parameter (or none).

◆ argsparse_check_option_type()

argsparse_check_option_type ( type  ,
value   
)

Check if a value matches a given type.

Return True if value is of type type.

Parameters
typeA case-insensitive type name.
valuea value to check.
Return values
0if the value matches the given type format.

◆ argsparse_describe_parameters()

argsparse_describe_parameters ( param...  )

Describe non-option positionnal parameters.

This function has currently 2 purposes:

  • enhance the "short" usage program description (see argsparse_usage_short())
  • compute the minimum and maximum numbers of non-option positionnal parameters and will overwrite previous settings using argsparse_minimum_parameters() and argsparse_maximum_parameters().
Parameters
param...a list of label describing positionnal parameters. These labels can have special forms such as:
  • "label?" a single optional non-repeatable parameter
  • "label+" a non-empty list of parameters
  • "label*" a potentially-empty list of parameters
  • "label" a single non-optional non-repeatable parameter
Return values
0

◆ argsparse_get_cumulative_array_name()

argsparse_get_cumulative_array_name ( option  )

Print the name of the array used for "cumulative" and "cumulativeset" options.

Parameters
optionan option name.

For "option-name" usually prints "cumulated_values_option_name".

◆ argsparse_option_to_identifier()

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.

Parameters
optionan option name.

Variable Documentation

◆ argsparse_pgm

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.