Skip to content

Commit 8bb10c9

Browse files
committed
Default-initialize _supplied_arg_<x>=0 for ARGBASH_INDICATE_SUPPLIED
1 parent a7e783e commit 8bb10c9

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

doc/guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Special arguments
312312

313313
This macro will cause a variable to be set if the argument was explicitly provided. This only works for optional arguments.
314314

315-
For example, if you have `ARG_OPTIONAL_BOOLEAN([quiet], , , [off])`, followed by `ARGBASH_INDICATE_SUPPLIED([quiet])`, then if `--quiet` was provided on the command line the variable `_supplied_arg_quiet=1` would be set. This allows you to see if an argument was explicitly provided using `[[ -v _supplied_arg_quiet ]]` or `[ "${_supplied_arg_quiet-x}" = 1 ]`.
315+
For example, if you have `ARG_OPTIONAL_BOOLEAN([quiet], , , [off])`, followed by `ARGBASH_INDICATE_SUPPLIED([quiet])`, then if `--quiet` was provided on the command line the variable `_supplied_arg_quiet=1` would be set. This allows you to see if an argument was explicitly provided using `[ "$_supplied_arg_quiet" = 1 ]`. If the argument was not passed to the program then this variable will be set to `0`.
316316

317317
Typing macros
318318
+++++++++++++

src/stuff.m4

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,10 @@ m4_define([_MAKE_DEFAULTS_OPTIONAL], [m4_do(
12431243
[action], [],
12441244
[incr], [_arg_varname=m4_expand(_default)_ENDL_],
12451245
[repeated], [_arg_varname=(_default)_ENDL_],
1246-
[_arg_varname=_sh_quote(_default)_ENDL_])],
1246+
[m4_do(
1247+
[_arg_varname=_sh_quote(_default)_ENDL_],
1248+
[m4_list_contains([HAVE_SUPPLIED], _argname, [[_supplied]_arg_varname=0]_ENDL_, [])],
1249+
)])],
12471250
)])],
12481251
)])
12491252

tests/regressiontests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ test-simple: $(TESTDIR)/test-simple.sh
372372
ERROR="[Nn]ot enough" $(REVERSE) $<
373373
ERROR="require exactly 1" $(REVERSE) $<
374374
$< pos -o 'uf ta' | grep -q 'OPT_S=uf ta,POS_S=pos,'
375-
$< pos -o 'uf ta' --print-optionals | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=x,_supplied_arg_not_supplied=x'
375+
$< pos -o 'uf ta' --print-optionals | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=0,_supplied_arg_not_supplied=x'
376376
$< pos -o 'uf ta' --print-optionals --la x | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=1,_supplied_arg_not_supplied=x'
377377
$< pos -o 'uf ta' --print-optionals --la x --not-supplied | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=1,_supplied_arg_not_supplied=x'
378378
test -z "$(SHELLCHECK)" || $(SHELLCHECK) "$(TESTDIR)/test-simple.sh"

tests/regressiontests/make/tests/tests-base.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ m4_define([test_simple_body], [[
144144

145145
ADD_TEST_BASH([test-simple], [test_simple_body
146146
$< pos -o 'uf ta' | grep -q 'OPT_S=uf ta,POS_S=pos,'
147-
$< pos -o 'uf ta' --print-optionals | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=x,_supplied_arg_not_supplied=x'
147+
$< pos -o 'uf ta' --print-optionals | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=0,_supplied_arg_not_supplied=x'
148148
$< pos -o 'uf ta' --print-optionals --la x | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=1,_supplied_arg_not_supplied=x'
149149
$< pos -o 'uf ta' --print-optionals --la x --not-supplied | grep -q '_supplied_arg_prefix=1,_supplied_arg_print_optionals=1,_supplied_arg_la=1,_supplied_arg_not_supplied=x'
150150
])

tests/regressiontests/test-simple.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
# Now we take the parsed data and assign them no nice-looking variable names,
1818
# sometimes after a basic validation
1919
if [ "$_arg_print_optionals" = on ]; then
20-
echo "_supplied_arg_prefix=${_supplied_arg_prefix-x},_supplied_arg_print_optionals=${_supplied_arg_print_optionals-x},_supplied_arg_la=${_supplied_arg_la-x},_supplied_arg_not_supplied=${_supplied_arg_not_supplied-x}"
20+
set -u
21+
echo "_supplied_arg_prefix=${_supplied_arg_prefix},_supplied_arg_print_optionals=${_supplied_arg_print_optionals},_supplied_arg_la=${_supplied_arg_la},_supplied_arg_not_supplied=${_supplied_arg_not_supplied-x}"
2122
else
2223
echo "OPT_S=$_arg_prefix,POS_S=$_arg_pos_arg,LA=$_arg_la,"
2324
fi

0 commit comments

Comments
 (0)