Skip to content

Commit 35047ee

Browse files
author
Damien Nadé
committed
argsparse_describe_parameters: now a public function, will full docstring and will also compute mim/max parameter numbers
1 parent bf92d82 commit 35047ee

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

argsparse.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ argsparse_minimum_parameters() {
326326
## @details The default maximum parameters requirement for command
327327
## line. "Should be enough for everyone".
328328
## @ingroup ArgsparseParameter
329-
declare -i __argsparse_maximum_parameters=100000
329+
declare -i __argsparse_maximum_parameters=1000000
330330

331331
## @fn argsparse_maximum_parameters()
332332
## @brief Set the maximum number of non-option parameters expected on
@@ -615,28 +615,54 @@ argsparse_usage_short() {
615615

616616
declare -a __argsparse_parameters_description
617617

618-
__argsparse_describe_parameters() {
618+
## @fn argsparse_describe_parameters()
619+
## @brief Describe non-option positionnal parameters.
620+
## @details
621+
## This function has currently 2 purposes:
622+
## @li enhance the "short" usage program description (see
623+
## argsparse_usage_short())
624+
## @li compute the minimum and maximum numbers of non-option
625+
## positionnal parameters and will overwrite previous settings using
626+
## argsparse_minimum_parameters() and argsparse_maximum_parameters().
627+
##
628+
## @param param... a list of label describing positionnal
629+
## parameters. These labels can have special forms such as:
630+
## @li "label?" a single optional non-repeatable parameter
631+
## @li "label+" a non-empty list of parameters
632+
## @li "label*" a potentially-empty list of parameters
633+
## @li "label" a single non-optional non-repeatable parameter
634+
## @retval 0
635+
argsparse_describe_parameters() {
619636
[[ $# -eq 0 ]] && return
620637
local param last name
638+
local -i min=0 max=0
621639
__argsparse_parameter_description=( "[--]" )
622640
for param in "$@"
623641
do
624642
name=${param%?}
625643
last=${param#$name}
626644
case "$last" in
627645
'?')
646+
: maximum param $((++max))
628647
__argsparse_parameters_description+=( "[ $name ]" )
629648
;;
630649
'*')
650+
max=1000000
631651
__argsparse_parameters_description+=( "[ $name ... ]" )
632652
;;
633653
+)
654+
max=1000000
655+
: minimum param $((++min))
634656
__argsparse_parameters_description+=( "$name [ $name ... ]" )
635657
;;
636658
*)
659+
: maximum param $((++max))
660+
: minimum param $((++min))
637661
__argsparse_parameters_description+=( "$param" )
638662
esac
639663
done
664+
argsparse_minimum_parameters "$min"
665+
argsparse_maximum_parameters "$max"
640666
}
641667

642668
## @fn argsparse_usage_long()

0 commit comments

Comments
 (0)