Skip to content

Commit fe5baa7

Browse files
committed
make some minor documentation updates
1 parent 0dfcf23 commit fe5baa7

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

‎argsparse.sh

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,54 @@
8181
##
8282
## The currently supported properties are:
8383
##
84-
## @li "hidden" @n
84+
## - "hidden" @n
8585
## An hidden option will not be shown in usage.
8686
##
87-
## @li "mandatory" @n
87+
## - "mandatory" @n
8888
## An option marked as mandatory is required on the command line. If
8989
## a mandatory option is omited by the user, usage() will be
9090
## triggered by argsparse_parse_options().
9191
##
92-
## @li "value" @n
92+
## - "value" @n
9393
## On the command line, the option will require a value.
9494
## Same effect if you end your optstring with a ':' char.
9595
##
96-
## @li "default:<defaultvalue>" @n
96+
## - "default:<defaultvalue>" @n
9797
## The default value for the option.
9898
##
99-
## @li "short:<char>" @n
99+
## - "short:<char>" @n
100100
## The short single-letter equivalent of the option.
101101
##
102-
## @li "type:<typename>" @n
102+
## - "type:<typename>" @n
103103
## Give a type to the option value. User input value will be checked
104104
## against built-in type verifications _or_ the
105105
## "check_type_<typename>" function. You cannot override a built-in
106106
## 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+
## .
107130
##
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
115132
## The exclude property value is a space-separated list of other
116133
## options. User wont be able to provided two mutually exclusive
117134
## options on the command line. @n
@@ -123,7 +140,7 @@
123140
## This foo exclude property setting wouldnt make --opt1 and --opt2,
124141
## mutually exclusive though.
125142
##
126-
## @li "alias:<option> <option>" @n
143+
## - "alias:<option> <option>" @n
127144
## This property allows an option to set multiple other without-value
128145
## options instead. Recursive aliases are permitted but no loop
129146
## detection is made, so be careful. @n
@@ -132,7 +149,7 @@
132149
## Then if the user is doing --opt on the command line, it will be as
133150
## if he would have done --opt1 --opt2
134151
##
135-
## @li cumulative @n
152+
## - cumulative @n
136153
## Implies 'value'.
137154
## Everytime a cumulative option "optionname" is passed on the
138155
## command line, the value is stored at the end of an array named
@@ -146,7 +163,7 @@
146163
## expand to value1, and ${cumulated_values_opt1[1]} will expand to
147164
## value2.
148165
##
149-
## @li cumulativeset @n
166+
## - cumulativeset @n
150167
## Exactly like cumulative, except only uniq values are kept. @n
151168
##
152169
## e.g: for a script with an opt1 option declared this way:
@@ -157,7 +174,7 @@
157174
## expand to value1, and "${cumulated_values_opt1[1]}" will expand to
158175
## value2. There would be no "${cumulated_values_opt1[2]}" value.
159176
##
160-
## @li "require:<option> <option>" @n
177+
## - "require:<option> <option>" @n
161178
## Creates a dependency between options. if you declare an option with:
162179
## @code
163180
## argsparse_use_option opt1 "something" require:"opt2 opt3"
@@ -176,9 +193,9 @@
176193
## argsparse_parse_options() with the all script parameters. This will
177194
## define:
178195
##
179-
## @li program_params, an array, containing all non-option parameters.
196+
## - program_params, an array, containing all non-option parameters.
180197
##
181-
## @li program_options, an associative array. For each record of the
198+
## - program_options, an associative array. For each record of the
182199
## array:
183200
## - The key is the long option name.
184201
## - And about values:
@@ -193,6 +210,7 @@
193210
## - If option is cumulative (or cumulativeset), the array record
194211
## value is the number of values passed by the user.
195212
## .
213+
##
196214
## After argsparse_parse_options() invokation, you can check if an
197215
## option have was on the command line (or not) using the
198216
## argsparse_is_option_set() function. @n
@@ -211,21 +229,20 @@
211229
## which may be removed or overridden by the sourcing program
212230
## afterwards.
213231
##
214-
##
215232
## @par Value setting internal logic
216233
## During option parsing, for every option of the form '--optionname'
217234
## expecting a value:
218235
##
219-
## @li If there exists an array named "option_<optionname>_values" and
236+
## - If there exists an array named "option_<optionname>_values" and
220237
## the user-given value doesn't belong to that array, then the
221238
## argsparse_parse_options() function immediately returns with
222239
## non-zero status, triggering 'usage'.
223240
##
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
225242
## the option has a type property field, then the value format will
226243
## be checked against that type.
227244
##
228-
## @li If a function named "check_value_of_<optionname>" has been
245+
## - If a function named "check_value_of_<optionname>" has been
229246
## defined, it will be called with the user-given value as its first
230247
## positionnal parameter. If check_value_of_<optionname> returns
231248
## with non-zero status, then parse_option immediately returns with
@@ -235,7 +252,7 @@
235252
## Also, still during option parsing and for @b every option of the form
236253
## "--optionname":
237254
##
238-
## @li After value-checking, if a function named
255+
## - After value-checking, if a function named
239256
## "set_option_<optionname>" exists, then, instead of directly
240257
## modifying the "program_options" associative array, this function
241258
## is automatically called with 'optionname' as its first
@@ -244,9 +261,9 @@
244261
##
245262
## @par About functions return values...
246263
##
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.
250267
##
251268
## @defgroup ArgsparseUsage Calling program usage description message.
252269
## @defgroup ArgsparseOptionSetter Setting options values.
@@ -524,9 +541,9 @@ argsparse_set_alias() {
524541
## @param option The option being set.
525542
## @param value the value of the option (optional).
526543
## @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.
530547
## @ingroup ArgsparseOptionSetter
531548
argsparse_set_option() {
532549
[[ $# -eq 2 || $# -eq 1 ]] || return 1
@@ -628,21 +645,21 @@ declare -a __argsparse_parameters_description
628645

629646
## @fn argsparse_describe_parameters()
630647
## @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
634650
## argsparse_usage_short())
635-
## @li compute the minimum and maximum numbers of non-option
651+
## - compute the minimum and maximum numbers of non-option
636652
## positionnal parameters and will overwrite previous settings using
637653
## argsparse_minimum_parameters() and argsparse_maximum_parameters().
638654
##
639655
## @param param... a list of label describing positionnal
640656
## 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
645661
## @retval 0
662+
## @ingroup ArgsparseUsage
646663
argsparse_describe_parameters() {
647664
[[ $# -eq 0 ]] && return
648665
local param last name
@@ -1299,8 +1316,9 @@ __argsparse_parse_options_no_usage() {
12991316
## @details
13001317
## After argsparse_parse_options(), it will contain (if no hook is set
13011318
## 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+
## .
13041322
## the command line", else.
13051323
declare -A program_options=()
13061324

@@ -1462,21 +1480,21 @@ __argsparse_check_declaration_conflict() {
14621480
## @fn argsparse_use_option()
14631481
## @brief Define a @b new option.
14641482
## @param optstring an optstring.
1465-
## @param description the option description, for the usage function.
1483+
## @param description the option description, for the usage() function.
14661484
## @param property... an non-ordered list of keywords. Recognized
14671485
## property keywords are:
1468-
## @li mandatory: missing option will trigger usage. If a default
1486+
## - mandatory: missing option will trigger usage. If a default
14691487
## value is given, the option is considered as if provided on
14701488
## 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
14751493
## 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
14801498
## default value for the option. All other parameters and
14811499
## values will be ignored. - might be broken / obsolete and broken
14821500
## @retval 0 if no error is encountered.

0 commit comments

Comments
 (0)