You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bin/argbash
+24-25Lines changed: 24 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,22 @@
4
4
# SC2016: Expressions don't expand in single quotes, use double quotes for that.
5
5
# SC2059 Don't use variables in the printf format string.
6
6
7
-
version=2.7.1
8
-
9
7
10
8
# DEFINE_SCRIPT_DIR()
11
9
# ARG_POSITIONAL_SINGLE([input],[The input template file (pass '-' for stdin)])
12
10
# ARG_OPTIONAL_SINGLE([output],[o],[Name of the output file (pass '-' for stdout)],[-])
13
11
# ARG_OPTIONAL_SINGLE([type],[t],[Output type to generate],[bash-script])
14
-
# ARG_OPTIONAL_BOOLEAN([library],[],[Whether the input file if the pure parsing library.])
15
-
# ARG_OPTIONAL_SINGLE([strip],[],[Determines what to have in the output.],[none])
12
+
# ARG_OPTIONAL_BOOLEAN([library],[],[Whether the input file if the pure parsing library])
13
+
# ARG_OPTIONAL_SINGLE([strip],[],[Determines what to have in the output],[none])
16
14
# ARG_OPTIONAL_BOOLEAN([check-typos],[],[Whether to check for possible argbash macro typos],[on])
17
15
# ARG_OPTIONAL_BOOLEAN([commented],[c],[Commented mode - include explanatory comments with the parsing code],[off])
18
16
# ARG_OPTIONAL_REPEATED([search],[I],[Directories to search for the wrapped scripts (directory of the template will be added to the end of the list)],["."])
19
17
# ARG_OPTIONAL_SINGLE([debug],[],[(developer option) Tell autom4te to trace a macro])
die "Value '$_seeking' (of argument '$2') doesn't match the list of allowed values: 'bash-script', 'posix-script', 'completion' and 'docopt'" 4
60
+
die "Value '$_seeking' (of argument '$2') doesn't match the list of allowed values: 'bash-script', 'posix-script', 'manpage', 'manpage-defs', 'completion' and 'docopt'" 4
printf'\t%s\n'"<input>: The input template file (pass '-' for stdin)"
92
90
printf'\t%s\n'"-o, --output: Name of the output file (pass '-' for stdout) (default: '-')"
93
91
printf'\t%s\n'"-t, --type: Output type to generate (default: 'bash-script')"
94
-
printf'\t%s\n'"--library, --no-library: Whether the input file if the pure parsing library. (off by default)"
95
-
printf'\t%s\n'"--strip: Determines what to have in the output. (default: 'none')"
92
+
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')"
96
94
printf'\t%s\n'"--check-typos, --no-check-typos: Whether to check for possible argbash macro typos (on by default)"
97
95
printf'\t%s\n'"-c, --commented, --no-commented: Commented mode - include explanatory comments with the parsing code (off by default)"
98
96
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:"
99
97
printf" '%s'""."
100
98
printf')\n'
101
99
printf'\t%s\n'"--debug: (developer option) Tell autom4te to trace a macro (no default)"
102
-
printf'\t%s\n'"-v, --version: Prints version"
103
100
printf'\t%s\n'"-h, --help: Prints help"
101
+
printf'\t%s\n'"-v, --version: Prints version"
104
102
}
105
103
106
104
@@ -180,14 +178,6 @@ parse_commandline()
180
178
--debug=*)
181
179
_arg_debug="${_key##--debug=}"
182
180
;;
183
-
-v|--version)
184
-
echo"argbash v$version"
185
-
exit 0
186
-
;;
187
-
-v*)
188
-
echo"argbash v$version"
189
-
exit 0
190
-
;;
191
181
-h|--help)
192
182
print_help
193
183
exit 0
@@ -196,6 +186,14 @@ parse_commandline()
196
186
print_help
197
187
exit 0
198
188
;;
189
+
-v|--version)
190
+
printf'%s %s\n\n%s\n'"argbash""2.7.1"'Argbash is an argument parser generator for Bash.'
191
+
exit 0
192
+
;;
193
+
-v*)
194
+
printf'%s %s\n\n%s\n'"argbash""2.7.1"'Argbash is an argument parser generator for Bash.'
195
+
exit 0
196
+
;;
199
197
*)
200
198
_last_positional="$1"
201
199
_positionals+=("$_last_positional")
@@ -295,14 +293,15 @@ interpret_error()
295
293
# $2: The original intended output file
296
294
define_file_metadata()
297
295
{
298
-
local _defines='' _input_dirname _output_dirname
296
+
local _defines='' _intended_destination="$ARGBASH_INTENDED_DESTINATION" _input_dirname _output_dirname
297
+
test -n "$_intended_destination"|| _intended_destination="$2"
@@ -296,6 +298,7 @@ Typically, you generate bash completion ``my-script.sh`` from the generated scri
296
298
297
299
and you move the created completion file ``my-script.sh`` to ``/etc/bash_completion.d/`` directory.
298
300
301
+
299
302
.. _docopt_output:
300
303
301
304
Docopt help message
@@ -315,6 +318,27 @@ Typically, you generate docopt output to the standard output from the generated
315
318
$ argbash my-script --type docopt --strip all
316
319
317
320
321
+
Manpage output
322
+
++++++++++++++
323
+
324
+
Argbash can generate source for the manual page for your script.
325
+
There are two files in the process --- the template, and definitions.
326
+
Those two files are in the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ format, and the template is supposed to be processed by the `rst2man <http://docutils.sourceforge.net/sandbox/manpage-writer/rst2man.txt>`_ utility.
327
+
328
+
The manpage template is supposed to be generated as script's metadata change, definitions are required to be maintained manually, as they are supposed to contain content that is not present in the script.
329
+
You can regenerate the template using the ``manpage`` output, while you are probably going to use the ``manpage-defs`` once to get you kickstarted and then continue to maintain it manually.
330
+
331
+
So given a argbash-powered script or m4 file, your manpage workflow will typically look like this:
332
+
333
+
.. code-block:: shell-session
334
+
335
+
$ argbash my-script --type manpage-defs --strip all -o my-script-defs.rst
336
+
$ argbash my-script --type manpage --strip all -o my-script.rst
337
+
$ vim my-script-defs.rst # Edit the definitions file
Argbash is a code generator that typically generates a bash argument-parsing library tailor-made for your script.
8
+
It lets you to describe arguments your script should take and then, you can generate the ``bash`` parsing code.
9
+
It stays in your script by default, but you can have it generated to a separate file and let ``bash`` to include it in your script for you.
10
+
``Argbash`` is very simple to use and the generated code is relatively nice to read.
11
+
Moreover, argument definitions stay embedded in the script, so when you need to update the parsing logic, you just re-run the ``argbash`` script on the already generated script.
12
+
13
+
.. |OPTION_OUTPUT| replace:: \
14
+
15
+
.. |OPTION_TYPE| replace:: Check out the documentation to learn about all argbash capabilities that are supported.
16
+
17
+
.. |OPTION_LIBRARY| replace:: This option is deprecated and it is the same as ``--strip user-content``.
18
+
19
+
.. |OPTION_STRIP| replace::
20
+
You can either strip ``none``, which is useful for scripts.
21
+
If you strip ``user-content``, you keep the Argbash header.
22
+
If you strip ``all``, you will have only the generated content in the result.
0 commit comments