Skip to content

Commit 59cfef6

Browse files
authored
Merge pull request #88 from matejak/set_completion
Improved help message.
2 parents f5fd1b6 + f0d69af commit 59cfef6

File tree

11 files changed

+70
-22
lines changed

11 files changed

+70
-22
lines changed

ChangeLog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
2.8.1 (TBA)
2-
-----------
2+
------------------
3+
4+
New features:
5+
6+
* The help message now contains reference for one-of argument types (#76).
37

48
Bugfixes:
59

bin/argbash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ print_help()
8888
printf 'Usage: %s [-o|--output <arg>] [-t|--type <type>] [--(no-)library] [--strip <content>] [--(no-)check-typos] [-c|--(no-)commented] [-I|--search <arg>] [--debug <arg>] [-h|--help] [-v|--version] <input>\n' "$0"
8989
printf '\t%s\n' "<input>: The input template file (pass '-' for stdin)"
9090
printf '\t%s\n' "-o, --output: Name of the output file (pass '-' for stdout) (default: '-')"
91-
printf '\t%s\n' "-t, --type: Output type to generate (default: 'bash-script')"
91+
printf '\t%s\n' "-t, --type: Output type to generate. Can be one of: 'bash-script', 'posix-script', 'manpage', 'manpage-defs', 'completion' and 'docopt' (default: 'bash-script')"
9292
printf '\t%s\n' "--library, --no-library: Whether the input file if the pure parsing library (off by default)"
93-
printf '\t%s\n' "--strip: Determines what to have in the output (default: 'none')"
93+
printf '\t%s\n' "--strip: Determines what to have in the output. Can be one of: 'none', 'user-content' and 'all' (default: 'none')"
9494
printf '\t%s\n' "--check-typos, --no-check-typos: Whether to check for possible argbash macro typos (on by default)"
9595
printf '\t%s\n' "-c, --commented, --no-commented: Commented mode - include explanatory comments with the parsing code (off by default)"
9696
printf '\t%s' "-I, --search: Directories to search for the wrapped scripts (directory of the template will be added to the end of the list) (default array elements:"

bin/argbash-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ print_help()
7777
printf '\t%s\n' "--opt: Add an single-valued optional argument (empty by default)"
7878
printf '\t%s\n' "--opt-bool: Add an optional boolean argument (empty by default)"
7979
printf '\t%s\n' "--wrap: What script(s) to wrap (empty by default)"
80-
printf '\t%s\n' "-m, --mode: The slider between feature-rich and simple script. (default: 'default')"
80+
printf '\t%s\n' "-m, --mode: The slider between feature-rich and simple script.. Can be one of: 'default', 'full' and 'minimal' (default: 'default')"
8181
printf '\t%s\n' "-v, --version: Prints version"
8282
printf '\t%s\n' "-h, --help: Prints help"
8383
}

doc/usage.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ The basename is inferred either from the source filename, or from the destinatio
285285
.. note::
286286

287287
The general recommendation is not to save your scripts to files without suffixes.
288-
Keep the ``.sh`` suffixe only for files that are Bash modules.
288+
Keep the ``.sh`` suffix only for files that are Bash modules.
289289

290290
After you generate the completion file, put it in the appropriate place (which may vary depending on your environment).
291291
In order to use it right away, simply source it.
@@ -298,6 +298,11 @@ Typically, you generate bash completion ``my-script.sh`` from the generated scri
298298
299299
and you move the created completion file ``my-script.sh`` to ``/etc/bash_completion.d/`` directory.
300300

301+
.. note::
302+
303+
Completion is not implemented for positional arguments.
304+
The corresponding Bash completion algorithm has to be much more complex in order to distinguish between 1st, 2nd etc. positional arguments.
305+
301306

302307
.. _docopt_output:
303308

src/argument_value_types.m4

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ argbash_api([ARG_TYPE_GROUP_SET], [m4_do(
7373
)])
7474

7575

76+
dnl
77+
dnl $1: Argname
78+
dnl $2: If it is of the set type
79+
dnl $3: If it is NOT of the set type
80+
m4_define([_IF_ARG_IS_OF_SET_TYPE], [m4_set_contains([GROUP_SET_ARGS], [$1], [$2], [$3])])
81+
82+
83+
m4_define([LIST_OF_VALUES_OF_ARGNAME], [[_LIST_]m4_quote(m4_indir([$1_VAL_TYPE]))])
84+
85+
7686
dnl
7787
dnl The common stuff to perform when adding a typed group
7888
dnl Registers the argument-type pair to be retreived by _GET_VALUE_TYPE or _GET_VALUE_STR

src/docopt.m4

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
m4_include([argument_value_types.m4])
2+
m4_include([value_validators.m4])
3+
4+
dnl
5+
dnl $1: Argname
6+
m4_define([_REPRESENT_VALUE_VERBOSE], [_IF_ARG_IS_OF_SET_TYPE([$1],
7+
[m4_list_join(LIST_OF_VALUES_OF_ARGNAME([$1]), [|])],
8+
[_CAPITALIZE([$1])])])
9+
10+
11+
dnl
12+
dnl $1: Argname
13+
m4_define([_REPRESENT_VALUE_SYNOPSIS], [m4_set_contains([TYPED_ARGS], [$1],
14+
[m4_indir([$1_VAL_GROUP])],
15+
[_CAPITALIZE([$1])])])
16+
117

218
m4_define([_SYNOPSIS_OF_OPTIONAL_ARGS], [m4_lists_foreach_optional([_ARGS_LONG,_ARGS_SHORT,_ARGS_CATH], [_argname,_arg_short,_arg_type], [m4_do(
319
[ @<:@],
420
[m4_case(_arg_type,
521
[bool], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, )],
6-
[arg], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, , _CAPITALIZE(_argname))],
7-
[repeated], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, , _CAPITALIZE(_argname))],
22+
[arg], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, , _REPRESENT_VALUE_SYNOPSIS(_argname))],
23+
[repeated], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, , _REPRESENT_VALUE_SYNOPSIS(_argname))],
824
[_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS(_argname, )])],
925
[@:>@],
1026
[m4_case(_arg_type,
@@ -38,7 +54,7 @@ m4_define([APPEND_TO_LISTS_WITH_HELP_ELEMENTS], [m4_do(
3854
[m4_list_append([_LIST_DOCOPT_OPTIONALS_SPECS], m4_case(_arg_type,
3955
[bool], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS([$1], [$2], , [, ])],
4056
[action], [_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS([$1], [$2], , [, ])],
41-
[_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS([$1], [$2], _CAPITALIZE([$1]), [, ])]))],
57+
[_FORMAT_OPTIONAL_ARGUMENT_FOR_HELP_SYNOPSIS([$1], [$2], _REPRESENT_VALUE_VERBOSE([$1]), [, ])]))],
4258
[m4_list_append([_LIST_LOCAL_DEFAULTS], m4_case(_arg_type,
4359
[bool], [[$4]],
4460
[action], [],

src/output-completion.m4

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ m4_define([_OUTER_CASE_ELEMENTS], [m4_do(
106106
)),
107107
)],
108108
)])],
109-
[_JOIN_INDENTED(2,
110-
[m4_list_join([OPTIONS_FOLLOWED_BY_SOME_VALUE], [|])[@:}@]],
111-
_INDENT_MORE(m4_dquote_elt(
112-
[COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )],
113-
[return 0],
114-
[;;],
115-
)),
116-
)],
109+
[m4_list_ifempty([OPTIONS_FOLLOWED_BY_SOME_VALUE], ,
110+
[_JOIN_INDENTED(2,
111+
[m4_list_join([OPTIONS_FOLLOWED_BY_SOME_VALUE], [|])[@:}@]],
112+
_INDENT_MORE(m4_dquote_elt(
113+
[COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )],
114+
[return 0],
115+
[;;],
116+
)),
117+
)])],
117118
[_JOIN_INDENTED(1,
118119
[_INDENT_()[*@:}@]],
119120
)],

src/stuff.m4

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,26 @@ m4_define([_MAKE_HELP_SYNOPSIS], [m4_do(
222222
)])
223223

224224

225+
dnl
226+
dnl $1: Argname
227+
dnl $2: Prelude
228+
m4_define([GET_SET_ARG_HELP_MESSAGE],
229+
[[$2]m4_list_join(LIST_OF_VALUES_OF_ARGNAME([$1]), [, ], ', ', [ and ])])
230+
231+
225232
m4_define([_MAKE_HELP_FUNCTION_POSITIONAL_PART], [m4_lists_foreach_positional(
226233
[_ARGS_LONG,_ARGS_CATH,_POSITIONALS_MINS,_POSITIONALS_DEFAULTS,_ARGS_HELP],
227234
[argname0,_arg_type,_min_argn,_defaults,_msg], [m4_ifnblank(_msg, [m4_do(
228235
[dnl We would like something else for argname if the arg type is 'inf' and _INF_VARNAME is not empty
229236
],
230237
[m4_pushdef([argname1], <m4_dquote(argname0)[[]m4_ifnblank(m4_quote($][1), m4_quote(-$][1))]>)],
231238
[m4_pushdef([argname], m4_if(_arg_type, [inf], [m4_default(_INF_REPR, argname1)], [[argname1($][@)]]))],
239+
[_IF_ARG_IS_OF_SET_TYPE(argname0, [m4_define([_msg], m4_dquote(_msg[]GET_SET_ARG_HELP_MESSAGE(argname0, [. Can be one of: ])))])],
232240
[_INDENT_()[printf '\t%s\n' "]argname[: ]_SUBSTITUTE_LF_FOR_NEWLINE_WITH_DISPLAY_INDENT_AND_ESCAPE_DOUBLEQUOTES(_msg)],
233241
[_POS_ARG_HELP_DEFAULTS([argname], _arg_type, _min_argn, _defaults)],
242+
["_ENDL_()],
234243
[m4_popdef([argname])],
235244
[m4_popdef([argname1])],
236-
["
237-
],
238245
)])])])
239246
240247
@@ -253,6 +260,7 @@ m4_define([_MAKE_PRINTF_OPTARG_HELP_STATEMENTS], [m4_do(
253260
[_GET_VALUE_DESC([$1])])])])],
254261
[m4_pushdef([_options], [$6([$1], [$2], [$3])])],
255262
[m4_pushdef([_help_msg], [_SUBSTITUTE_LF_FOR_NEWLINE_WITH_DISPLAY_INDENT_AND_ESCAPE_DOUBLEQUOTES([$5])])],
263+
[_IF_ARG_IS_OF_SET_TYPE([$1], [m4_pushdef([_help_msg], m4_quote(_help_msg[]GET_SET_ARG_HELP_MESSAGE([$1], [. Can be one of: ])))])],
256264
[m4_case([$3],
257265
[action],
258266
[_INDENT_()[printf '\t%s\n'] "_options: _help_msg"],
@@ -266,6 +274,7 @@ m4_define([_MAKE_PRINTF_OPTARG_HELP_STATEMENTS], [m4_do(
266274
_INDENT_()[printf " '%s'" $4]
267275
_INDENT_()[printf '@:}@\n']])],
268276
[_INDENT_()[printf '\t%s\n'] "_options: _help_msg[]m4_ifblank(_default, [[ (no default)]], [ ([default: ]'_default')])"])],
277+
[_IF_ARG_IS_OF_SET_TYPE([$1], [m4_popdef([_help_msg])])],
269278
[m4_popdef([_help_msg])],
270279
[m4_popdef([_options])],
271280
[m4_popdef([_type_spec])],

tests/regressiontests/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ test-group: $(TESTDIR)/test-group.sh
698698
ERROR="allowed" $(REVERSE) $< bar
699699
@# Assure that there is not the string '_idx' in the script since we don't want indices support in this test
700700
! grep -q _idx $<
701-
# $< -h | grep action | grep ACTION | grep -q 'foo,baz'
701+
$< -h | grep act-ion | grep -q "'foo,baz'"
702+
$< -h | grep act-ion | grep -q "'bar bar'"
702703
test -z "$(SHELLCHECK)" || $(SHELLCHECK) "$(TESTDIR)/test-group.sh"
703704
test-group-idx: $(TESTDIR)/test-group-idx.sh
704705
$< foo | grep -q "ACT=foo,IDX=0,"

tests/regressiontests/make/tests/tests-types.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ ADD_TEST_BASH([test-group], [[
2626
ERROR="allowed" $(REVERSE) $< bar
2727
@# Assure that there is not the string '_idx' in the script since we don't want indices support in this test
2828
! grep -q _idx $<
29-
# $< -h | grep action | grep ACTION | grep -q 'foo,baz'
29+
$< -h | grep act-ion | grep -q "'foo,baz'"
30+
$< -h | grep act-ion | grep -q "'bar bar'"
3031
]])
3132

3233
ADD_TEST_BASH([test-group-idx], [[

tests/regressiontests/test-group.m4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

3-
# ARG_POSITIONAL_SINGLE([act-ion], [], [foo])
3+
# ARG_POSITIONAL_SINGLE([act-ion], [help], [foo])
44
# ARG_TYPE_GROUP_SET([act_null], [ACTION], [act-ion], [foo,baz,bar bar,[foo,baz],])
5-
# ARG_OPTIONAL_REPEATED([repeated])
5+
# dnl The construction below is there for precise targeting of a sed substitution.
6+
# ARG_OPTIONAL_REPEATED([repeated][], , [help])
67
# ARG_TYPE_GROUP_SET([act_nonull], [ACTION2], [repeated], [foo,baz])
78
# ARG_HELP([Testing program])
89
# ARGBASH_GO

0 commit comments

Comments
 (0)