This document describes the functions and variables generated by build-shellscript
Any undocumented function you may find in a generated script should have to be considered as a private function.
Name | Parameters | Return value | Description | |
---|---|---|---|---|
parse() | argv | The number of error encountered | Parse the command line arguments and fill the options bound variable and the $parser_values array | |
parse_displayerrors() | None | 0 | Output all errors generated while parsing the command line | |
usage() | [topic] | 0 |
Print the program help string, generated from the information gathered in the XML program description file.
if topic is the name of a subcommand, usage will display the program's subcommand help string. |
Name | Type | Description | |
---|---|---|---|
$parser_shell | string | The name of the shell interpreter (example: bash) | |
$parser_startindex | int | Indicates what is the first valid index in a array variable (0 in bash, 1 in zsh) | |
$parser_subcommand | string | Name of the selected program subcommand. The name is always the one described by the <name /> element even if one of it aliases was used on the command line | |
$parser_values | array | Array of positional arguments which are not subcommand names, option names, option arguments nor special markers |
For each program option defined in the program interface XML definition file where a variable name is defined,
a shell variable of the same name is created with the following rules
Option type | Variable type | Default value | |
---|---|---|---|
Switch | Boolean | false | |
Single argument | String |
Value of <default/> if any,
Empty string otherwise |
|
Multi argument | Array | Empty | |
Group | String | Empty string |
After parsing, variables are modified as is
Option type | Value | |
---|---|---|
Switch | true if the option is present on the command line | |
Single argument | Value of the option argument if the option is present on the command line. | |
Multi argument | Values of the option arguments if the option is present on the command line. | |
Group |
If the group is exclusive: Name of the first sub option bound variable name found on the command line;
Otherwise, an empty string |
The program interface definition schema allows options of two subcommands to share the same bound variable name. To avoid name aliasing while generating the bash code, the subcommand option variable names can be prefixed with the name of the subcommand using the --prefix-sc-variables option of build-shellscript
If the subcommand sub has an option with a bound variable name myVar, the variable name will become sub_myVar.
Any option's bound variable can be modified prior to calling the parse function. This can be useful to set a default value which depends on dynamic data
We assume the program has a --help switch option with a bound variable name displayHelp
The first lines of your program should looks like
Let's say we are re-coding the mv utility. The n-1 positional arguments are the input files, the last positional argument is the output file or folder
To process positional arguments, use the ${parser_values} array
Three single-argument options in an exclusive group.
Since ${thirdArg} will always have a non-null value (due to the <default/> clause), we can't rely on variable emptyness to know which option the user selects. We have to use the group bound variable ${groupVariable}