]> git.corax.cc Git - toolbox/commitdiff
include/opt: Emit an error if a required parameter is missing
authorMatthias Kruk <m@m10k.eu>
Thu, 11 Aug 2022 12:47:38 +0000 (21:47 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 11 Aug 2022 12:47:38 +0000 (21:47 +0900)
When an option expecting a parameter is not passed one, `opt_parse()`
does not fail because of an incorrect comparison.

This commit fixes the comparison so that `opt_parse()` fails and
prints an error message when a required parameter is missing.

include/opt.sh

index ceebc5eae27142077401c5812f9590ccca48e847..5ed8d94ee250a7530d525527f9c8e09501fed792 100644 (file)
@@ -180,7 +180,7 @@ opt_parse() {
                if (( flags & __opt_flag_has_value )); then
                        ((i++))
 
-                       if (( i > ${#argv[@]} )); then
+                       if (( i >= ${#argv[@]} )); then
                                log_error "Missing argument after $param"
                                return 1
                        fi