|
81 | 81 | ##
|
82 | 82 | ## The currently supported properties are:
|
83 | 83 | ##
|
84 |
| -## @li "hidden" @n |
| 84 | +## - "hidden" @n |
85 | 85 | ## An hidden option will not be shown in usage.
|
86 | 86 | ##
|
87 |
| -## @li "mandatory" @n |
| 87 | +## - "mandatory" @n |
88 | 88 | ## An option marked as mandatory is required on the command line. If
|
89 | 89 | ## a mandatory option is omited by the user, usage() will be
|
90 | 90 | ## triggered by argsparse_parse_options().
|
91 | 91 | ##
|
92 |
| -## @li "value" @n |
| 92 | +## - "value" @n |
93 | 93 | ## On the command line, the option will require a value.
|
94 | 94 | ## Same effect if you end your optstring with a ':' char.
|
95 | 95 | ##
|
96 |
| -## @li "default:<defaultvalue>" @n |
| 96 | +## - "default:<defaultvalue>" @n |
97 | 97 | ## The default value for the option.
|
98 | 98 | ##
|
99 |
| -## @li "short:<char>" @n |
| 99 | +## - "short:<char>" @n |
100 | 100 | ## The short single-letter equivalent of the option.
|
101 | 101 | ##
|
102 |
| -## @li "type:<typename>" @n |
| 102 | +## - "type:<typename>" @n |
103 | 103 | ## Give a type to the option value. User input value will be checked
|
104 | 104 | ## against built-in type verifications _or_ the
|
105 | 105 | ## "check_type_<typename>" function. You cannot override a built-in
|
106 | 106 | ## type. Built-in types are:
|
| 107 | +## - file |
| 108 | +## - directory |
| 109 | +## - pipe |
| 110 | +## - terminal |
| 111 | +## - socket |
| 112 | +## - link |
| 113 | +## - char |
| 114 | +## - unsignedint |
| 115 | +## - uint |
| 116 | +## - integer |
| 117 | +## - int |
| 118 | +## - hexa |
| 119 | +## - ipv4 |
| 120 | +## - ipv6 |
| 121 | +## - ip |
| 122 | +## - hostname |
| 123 | +## - host |
| 124 | +## - portnumber |
| 125 | +## - port |
| 126 | +## - username |
| 127 | +## - group |
| 128 | +## - date |
| 129 | +## . |
107 | 130 | ##
|
108 |
| -## @code |
109 |
| -## file directory pipe terminal socket link char unsignedint uint |
110 |
| -## integer int hexa ipv4 ipv6 ip hostname host portnumber port |
111 |
| -## username group date |
112 |
| -## @endcode |
113 |
| -## |
114 |
| -## @li "exclude:<option> <option>" @n |
| 131 | +## - "exclude:<option> <option>" @n |
115 | 132 | ## The exclude property value is a space-separated list of other
|
116 | 133 | ## options. User wont be able to provided two mutually exclusive
|
117 | 134 | ## options on the command line. @n
|
|
123 | 140 | ## This foo exclude property setting wouldnt make --opt1 and --opt2,
|
124 | 141 | ## mutually exclusive though.
|
125 | 142 | ##
|
126 |
| -## @li "alias:<option> <option>" @n |
| 143 | +## - "alias:<option> <option>" @n |
127 | 144 | ## This property allows an option to set multiple other without-value
|
128 | 145 | ## options instead. Recursive aliases are permitted but no loop
|
129 | 146 | ## detection is made, so be careful. @n
|
|
132 | 149 | ## Then if the user is doing --opt on the command line, it will be as
|
133 | 150 | ## if he would have done --opt1 --opt2
|
134 | 151 | ##
|
135 |
| -## @li cumulative @n |
| 152 | +## - cumulative @n |
136 | 153 | ## Implies 'value'.
|
137 | 154 | ## Everytime a cumulative option "optionname" is passed on the
|
138 | 155 | ## command line, the value is stored at the end of an array named
|
|
146 | 163 | ## expand to value1, and ${cumulated_values_opt1[1]} will expand to
|
147 | 164 | ## value2.
|
148 | 165 | ##
|
149 |
| -## @li cumulativeset @n |
| 166 | +## - cumulativeset @n |
150 | 167 | ## Exactly like cumulative, except only uniq values are kept. @n
|
151 | 168 | ##
|
152 | 169 | ## e.g: for a script with an opt1 option declared this way:
|
|
157 | 174 | ## expand to value1, and "${cumulated_values_opt1[1]}" will expand to
|
158 | 175 | ## value2. There would be no "${cumulated_values_opt1[2]}" value.
|
159 | 176 | ##
|
160 |
| -## @li "require:<option> <option>" @n |
| 177 | +## - "require:<option> <option>" @n |
161 | 178 | ## Creates a dependency between options. if you declare an option with:
|
162 | 179 | ## @code
|
163 | 180 | ## argsparse_use_option opt1 "something" require:"opt2 opt3"
|
|
176 | 193 | ## argsparse_parse_options() with the all script parameters. This will
|
177 | 194 | ## define:
|
178 | 195 | ##
|
179 |
| -## @li program_params, an array, containing all non-option parameters. |
| 196 | +## - program_params, an array, containing all non-option parameters. |
180 | 197 | ##
|
181 |
| -## @li program_options, an associative array. For each record of the |
| 198 | +## - program_options, an associative array. For each record of the |
182 | 199 | ## array:
|
183 | 200 | ## - The key is the long option name.
|
184 | 201 | ## - And about values:
|
|
193 | 210 | ## - If option is cumulative (or cumulativeset), the array record
|
194 | 211 | ## value is the number of values passed by the user.
|
195 | 212 | ## .
|
| 213 | +## |
196 | 214 | ## After argsparse_parse_options() invokation, you can check if an
|
197 | 215 | ## option have was on the command line (or not) using the
|
198 | 216 | ## argsparse_is_option_set() function. @n
|
|
211 | 229 | ## which may be removed or overridden by the sourcing program
|
212 | 230 | ## afterwards.
|
213 | 231 | ##
|
214 |
| -## |
215 | 232 | ## @par Value setting internal logic
|
216 | 233 | ## During option parsing, for every option of the form '--optionname'
|
217 | 234 | ## expecting a value:
|
218 | 235 | ##
|
219 |
| -## @li If there exists an array named "option_<optionname>_values" and |
| 236 | +## - If there exists an array named "option_<optionname>_values" and |
220 | 237 | ## the user-given value doesn't belong to that array, then the
|
221 | 238 | ## argsparse_parse_options() function immediately returns with
|
222 | 239 | ## non-zero status, triggering 'usage'.
|
223 | 240 | ##
|
224 |
| -## @li If the "option_<optionname>_values" array does not exist, but if |
| 241 | +## - If the "option_<optionname>_values" array does not exist, but if |
225 | 242 | ## the option has a type property field, then the value format will
|
226 | 243 | ## be checked against that type.
|
227 | 244 | ##
|
228 |
| -## @li If a function named "check_value_of_<optionname>" has been |
| 245 | +## - If a function named "check_value_of_<optionname>" has been |
229 | 246 | ## defined, it will be called with the user-given value as its first
|
230 | 247 | ## positionnal parameter. If check_value_of_<optionname> returns
|
231 | 248 | ## with non-zero status, then parse_option immediately returns with
|
|
235 | 252 | ## Also, still during option parsing and for @b every option of the form
|
236 | 253 | ## "--optionname":
|
237 | 254 | ##
|
238 |
| -## @li After value-checking, if a function named |
| 255 | +## - After value-checking, if a function named |
239 | 256 | ## "set_option_<optionname>" exists, then, instead of directly
|
240 | 257 | ## modifying the "program_options" associative array, this function
|
241 | 258 | ## is automatically called with 'optionname' as its first
|
|
244 | 261 | ##
|
245 | 262 | ## @par About functions return values...
|
246 | 263 | ##
|
247 |
| -## All the functions will return with an error (usually a return code |
248 |
| -## of 1) if called with a wrong number of parameters, and return with |
249 |
| -## 0 if everything went fine. |
| 264 | +## All argsparse functions will return with an error (usually a return |
| 265 | +## code of 1) if called with a wrong number of parameters, and return |
| 266 | +## with 0 if everything went fine. |
250 | 267 | ##
|
251 | 268 | ## @defgroup ArgsparseUsage Calling program usage description message.
|
252 | 269 | ## @defgroup ArgsparseOptionSetter Setting options values.
|
@@ -524,9 +541,9 @@ argsparse_set_alias() {
|
524 | 541 | ## @param option The option being set.
|
525 | 542 | ## @param value the value of the option (optional).
|
526 | 543 | ## @details This function will be called by argsparse_parse_options()
|
527 |
| -## whenever an option is being and no custom setting hook is define |
528 |
| -## for this option. Depending of the properties of the option a more |
529 |
| -## specific setting hook will be called. |
| 544 | +## whenever a given option is being set and no custom setting hook is |
| 545 | +## defined for said option. Depending of the properties of the option, |
| 546 | +## a more specific setting hook will be called. |
530 | 547 | ## @ingroup ArgsparseOptionSetter
|
531 | 548 | argsparse_set_option() {
|
532 | 549 | [[ $# -eq 2 || $# -eq 1 ]] || return 1
|
@@ -628,21 +645,21 @@ declare -a __argsparse_parameters_description
|
628 | 645 |
|
629 | 646 | ## @fn argsparse_describe_parameters()
|
630 | 647 | ## @brief Describe non-option positionnal parameters.
|
631 |
| -## @details |
632 |
| -## This function has currently 2 purposes: |
633 |
| -## @li enhance the "short" usage program description (see |
| 648 | +## @details This function has currently 2 purposes: |
| 649 | +## - enhance the "short" usage program description (see |
634 | 650 | ## argsparse_usage_short())
|
635 |
| -## @li compute the minimum and maximum numbers of non-option |
| 651 | +## - compute the minimum and maximum numbers of non-option |
636 | 652 | ## positionnal parameters and will overwrite previous settings using
|
637 | 653 | ## argsparse_minimum_parameters() and argsparse_maximum_parameters().
|
638 | 654 | ##
|
639 | 655 | ## @param param... a list of label describing positionnal
|
640 | 656 | ## parameters. These labels can have special forms such as:
|
641 |
| -## @li "label?" a single optional non-repeatable parameter |
642 |
| -## @li "label+" a non-empty list of parameters |
643 |
| -## @li "label*" a potentially-empty list of parameters |
644 |
| -## @li "label" a single non-optional non-repeatable parameter |
| 657 | +## - "label?" a single optional non-repeatable parameter |
| 658 | +## - "label+" a non-empty list of parameters |
| 659 | +## - "label*" a potentially-empty list of parameters |
| 660 | +## - "label" a single non-optional non-repeatable parameter |
645 | 661 | ## @retval 0
|
| 662 | +## @ingroup ArgsparseUsage |
646 | 663 | argsparse_describe_parameters() {
|
647 | 664 | [[ $# -eq 0 ]] && return
|
648 | 665 | local param last name
|
@@ -1299,8 +1316,9 @@ __argsparse_parse_options_no_usage() {
|
1299 | 1316 | ## @details
|
1300 | 1317 | ## After argsparse_parse_options(), it will contain (if no hook is set
|
1301 | 1318 | ## for "optionname")
|
1302 |
| -## @li "optionname" -> "value", if "optionname" accepts a value. |
1303 |
| -## @li "optionname" -> "how many times the option has been detected on |
| 1319 | +## - "optionname" -> "value", if "optionname" accepts a value. |
| 1320 | +## - "optionname" -> "how many times the option has been detected on |
| 1321 | +## . |
1304 | 1322 | ## the command line", else.
|
1305 | 1323 | declare -A program_options=()
|
1306 | 1324 |
|
@@ -1462,21 +1480,21 @@ __argsparse_check_declaration_conflict() {
|
1462 | 1480 | ## @fn argsparse_use_option()
|
1463 | 1481 | ## @brief Define a @b new option.
|
1464 | 1482 | ## @param optstring an optstring.
|
1465 |
| -## @param description the option description, for the usage function. |
| 1483 | +## @param description the option description, for the usage() function. |
1466 | 1484 | ## @param property... an non-ordered list of keywords. Recognized
|
1467 | 1485 | ## property keywords are:
|
1468 |
| -## @li mandatory: missing option will trigger usage. If a default |
| 1486 | +## - mandatory: missing option will trigger usage. If a default |
1469 | 1487 | ## value is given, the option is considered as if provided on
|
1470 | 1488 | ## the command line.
|
1471 |
| -## @li hidden: option wont show in default usage function. |
1472 |
| -## @li value: option expects a following value. |
1473 |
| -## @li short:c: option has a single-lettered (c) equivalent. |
1474 |
| -## @li exclude:"option1 [ option2 ... ]" option is not |
| 1489 | +## - hidden: option wont show in default usage function. |
| 1490 | +## - value: option expects a following value. |
| 1491 | +## - short:c: option has a single-lettered (c) equivalent. |
| 1492 | +## - exclude:"option1 [ option2 ... ]" option is not |
1475 | 1493 | ## compatible with other options option1, option2...
|
1476 |
| -## @li cumulative |
1477 |
| -## @li cumulativeset |
1478 |
| -## @li type:sometype |
1479 |
| -## @li The @b last non-keyword parameter will be considered as the |
| 1494 | +## - cumulative |
| 1495 | +## - cumulativeset |
| 1496 | +## - type:sometype |
| 1497 | +## - The @b last non-keyword parameter will be considered as the |
1480 | 1498 | ## default value for the option. All other parameters and
|
1481 | 1499 | ## values will be ignored. - might be broken / obsolete and broken
|
1482 | 1500 | ## @retval 0 if no error is encountered.
|
|
0 commit comments