Skip to content

Commit

Permalink
Removed some bashisms, cleaned stray spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Jul 22, 2016
1 parent fac721a commit e35c170
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/argbash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _ARG_SEARCH=(".")
_ARG_DEBUG=

# THE PRINT HELP FUNCION
function print_help
print_help ()
{
echo "Argbash is an argument parser generator for Bash."
echo "Usage: $0 [-o|--output <arg>] [--(no-)standalone] [-I|--search] [--debug <arg>] [-v|--version] [-h|--help] <input>"
Expand Down
42 changes: 21 additions & 21 deletions src/stuff.m4
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ m4_define([_ARG_POSITIONAL_SINGLE], [m4_do(
)])


dnl
dnl
dnl Declare sequence of possibly infinitely many positional arguments
dnl $1: Name of the arg
dnl $2: Help for the arg
Expand All @@ -191,8 +191,8 @@ m4_define([ARG_POSITIONAL_INF], [m4_do(


m4_define([_CHECK_INTEGER_TYPE], [m4_do(
[m4_ifnblank([$1],
[m4_if(0, 1,
[m4_ifnblank([$1],
[m4_if(0, 1,
[m4_fatal([$2])],
[])])],
)])
Expand Down Expand Up @@ -438,18 +438,18 @@ m4_define([_POS_ARG_HELP_LINE], [m4_do(
m4_expand([@<:@<argname>@:>@]), m4_expand([<argname>])))],
[more], [m4_do(
[m4_if(_min_argn, 0, ,
[m4_for([idx2], 1, _min_argn, 1,
[m4_for([idx2], 1, _min_argn, 1,
[m4_list_add([_POSITIONALS_LIST], m4_expand([<argname-idx2>]))])])],
[m4_if(_min_argn, _max_argn, ,
[m4_for([idx2], m4_incr(_min_argn), _max_argn, 1,
[m4_if(_min_argn, _max_argn, ,
[m4_for([idx2], m4_incr(_min_argn), _max_argn, 1,
[m4_list_add([_POSITIONALS_LIST], m4_expand([@<:@<argname-idx2>@:>@]))])])])],
[inf], [m4_ifnblank(_INF_REPR, [m4_list_add([_POSITIONALS_LIST], _INF_REPR)], [m4_do(
[m4_if(_min_argn, 0, ,
[m4_for([idx2], 1, _min_argn, 1,
[m4_for([idx2], 1, _min_argn, 1,
[m4_list_add([_POSITIONALS_LIST], m4_expand([<argname-idx2>]))])])],
[m4_list_add([_POSITIONALS_LIST],
m4_expand([@<:@<argname[-]m4_incr(_min_argn)>@:>@]),
[...],
[m4_list_add([_POSITIONALS_LIST],
m4_expand([@<:@<argname[-]m4_incr(_min_argn)>@:>@]),
[...],
m4_expand([@<:@<argname[-]n>@:>@]),
[...])])])],
[m4_fatal([$0: Unhandled arg type: ]'_arg_type')])],
Expand All @@ -460,7 +460,7 @@ m4_define([_POS_ARG_HELP_LINE], [m4_do(
m4_define([_MAKE_USAGE_MORE], [m4_do(
[m4_list_ifempty(_defaults, , [m4_do(
[[ @{:@defaults for ]argname[-]m4_incr(_min_argn)],
[m4_if(m4_list_len(_defaults), 1, ,
[m4_if(m4_list_len(_defaults), 1, ,
[[ to ]argname[-]m4_eval(_min_argn + m4_list_len(_defaults))[ respectively]])],
[: ],
[m4_list_join(_defaults, [, ], ', ', [ and ])@:}@],
Expand All @@ -471,7 +471,7 @@ m4_define([_MAKE_USAGE_MORE], [m4_do(
m4_define([_POS_ARG_HELP_USAGE], [m4_do(
[m4_pushdef([_arg_type], m4_list_nth([_POSITIONALS_TYPES], idx))],
[m4_case(m4_expand([_arg_type]),
[single],
[single],
[m4_if(_min_argn, 0, [m4_do(
[ @{:@],
[default: '"],
Expand All @@ -490,7 +490,7 @@ dnl
dnl $1: arg index
dnl Returns either --long or -l|--long if there is that -l
m4_define([_ARG_FORMAT], [m4_do(
[m4_ifnblank(m4_list_nth([_ARGS_SHORT], idx),
[m4_ifnblank(m4_list_nth([_ARGS_SHORT], idx),
[-]m4_list_nth([_ARGS_SHORT], idx)|)],
[[--]m4_list_nth([_ARGS_LONG], idx)],
)])
Expand All @@ -501,7 +501,7 @@ dnl $1: The command short description
m4_define([_MAKE_HELP], [m4_do(
[# THE PRINT HELP FUNCION
],
[function print_help
[print_help ()
{
],
m4_ifnblank(m4_expand([_HELP_MSG]), m4_expand([[ echo] "_HELP_MSG"
Expand Down Expand Up @@ -581,11 +581,11 @@ m4_define([_MAKE_HELP], [m4_do(
],
[dnl Now the default is expanded since it is between double quotes
],
[m4_case(m4_list_nth([_ARGS_TYPE], idx),
[action], [],
[m4_case(m4_list_nth([_ARGS_TYPE], idx),
[action], [],
[bool], [ (m4_list_nth([_ARGS_DEFAULT], idx) by default)],
[repeated], [ (default array: m4_list_nth([_ARGS_DEFAULT], idx) )],
[m4_ifnblank(m4_list_nth([_ARGS_DEFAULT], idx), [default: 'm4_list_nth([_ARGS_DEFAULT], idx)'], [no default])])],
[ @{:@m4_ifnblank(m4_list_nth([_ARGS_DEFAULT], idx), [default: 'm4_list_nth([_ARGS_DEFAULT], idx)'], [no default])@:}@])],
["
],
)])])])],
Expand Down Expand Up @@ -647,7 +647,7 @@ m4_define([_EVAL_OPTIONALS], [m4_do(
[bool], _ARGVAR[="on"
_ADD_OPTS_VALS(m4_expand([_ARGVAR]))
test "$[]{1:0:5}" = "--no-" && ]_ARGVAR[="off"],
[incr], m4_quote((( _ARGVAR++ )))
[incr], m4_quote(_ARGVAR=$(($_ARGVAR + 1)))
_ADD_OPTS_VALS(m4_expand([_ARGVAR])),
[action], [m4_list_nth([_ARGS_DEFAULT], idx)
exit 0],
Expand Down Expand Up @@ -746,7 +746,7 @@ test ${#POSITIONALS[@]} -lt ]],
[m4_do(
[dnl If we allow up to infinitely many args, we prepare the array for it.
],
[(( OUR_ARGS=${#POSITIONALS@<:@@@:>@} - ${#POSITIONAL_NAMES@<:@@@:>@} ))
[OUR_ARGS=$((${#POSITIONALS@<:@@@:>@} - ${#POSITIONAL_NAMES@<:@@@:>@}))
],
[for (( ii = 0; ii < $OUR_ARGS; ii++))
do
Expand All @@ -755,7 +755,7 @@ done
],
)],
[m4_do(
[dnl If we allow up to infinitely many args, there is no point in warning about too many args.
[dnl If we allow up to infinitely many args, there is no point in warning about too many args.
],
[[test ${#POSITIONALS[@]} -gt ]],
[_POSITIONALS_MAX],
Expand Down Expand Up @@ -924,6 +924,6 @@ dnl Positional args wrapped:
dnl - we keep a list POS_WRAPPED, where we store names of positional args that we want record.
dnl - OR: When we encounter a wrapped positional arg, we store a code block <ARGS_ARRAY>+=pos_arg
dnl - and at the end, we just expand this block after pos_arg vars are filled.
dnl - after positional args are assigned, we go through this list and append to the array of passed wrapped args
dnl - after positional args are assigned, we go through this list and append to the array of passed wrapped args
dnl
dnl TODO: Implement leftover args
4 changes: 2 additions & 2 deletions tests/regressiontests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ test-infinity-mixed: $(TESTDIR)/test-infinity-mixed.sh
$< 1 2 "3 1 4" 4 5 | grep -q 'POS_S=1,2,3 1 4,4,5,'

test-leftovers: $(TESTDIR)/test-leftovers.sh
$< -h | grep -q '\[-c\|--cosi <arg>\] \[-h\|--help\] <another> \.\.\. $$'
$< -c ours --no-fear "ours pos" left "o ver" | grep -q 'OPT_S=ours,FEAR=off,POS_S=ours pos,LEFTOVERS=left,o ver,'
$< -h | grep -q '\[-c|--cosi <arg>\] \[--(no-)fear\] \[-m|--more\] \[-h|--help\] <another> \.\.\. $$'
$< -c ours -m --more --more --no-fear "ours pos" left "o ver" | grep -q 'MORE=3,OPT_S=ours,FEAR=off,POS_S=ours pos,LEFTOVERS=left,o ver,'

tests-clean:
$(RM) $(SCRIPTS)
Expand Down
4 changes: 2 additions & 2 deletions tests/regressiontests/test-leftovers.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# ARG_OPTIONAL_SINGLE([cosi], [c])
# ARG_OPTIONAL_BOOLEAN([fear])
# ARG_OPTIONAL_INCREMENTAL([more], m)
# ARG_POSITIONAL_SINGLE([another])
# ARG_LEFTOVERS([just leftovers])
# ARG_HELP()
Expand All @@ -12,11 +13,10 @@
# Now we take the parsed data and assign them no nice-looking variable names,
# sometimes after a basic validation

echo -n "OPT_S=$_ARG_COSI,FEAR=$_ARG_FEAR,POS_S=$_ARG_ANOTHER,LEFTOVERS="
echo -n "MORE=$_ARG_MORE,OPT_S=$_ARG_COSI,FEAR=$_ARG_FEAR,POS_S=$_ARG_ANOTHER,LEFTOVERS="
for val in "${_ARG_LEFTOVERS[@]}"
do echo -n "$val,"
done
echo

# closing escape square bracket: ]

0 comments on commit e35c170

Please sign in to comment.