Skip to content

Commit 2e2ec04

Browse files
committed
Documented the manpage output.
1 parent f8ed967 commit 2e2ec04

File tree

7 files changed

+84
-8
lines changed

7 files changed

+84
-8
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ New features:
77
* Allow scripts generated by argbash-init with complete separation (`-s -s`) to be run from a symbolic link.
88
* Double quotes in help messages are escaped (fixes #61).
99
* Introduced the `ARG_VERSION_AUTO` macro.
10+
* Enabled manpage output consumable by the `rst2man` utility.
1011

1112

1213
2.7.1 (2018-08-15)

doc/usage.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ POSIX script posix-script none
246246
POSIX script parsing section posix-script user-content
247247
Bash completion completion all
248248
docopt help message docopt all
249+
manpage template manpage all
250+
manpage template definitions manpage-defs all
249251
============================ ======================= ==========================
250252

251253

@@ -296,6 +298,7 @@ Typically, you generate bash completion ``my-script.sh`` from the generated scri
296298
297299
and you move the created completion file ``my-script.sh`` to ``/etc/bash_completion.d/`` directory.
298300

301+
299302
.. _docopt_output:
300303

301304
Docopt help message
@@ -315,6 +318,27 @@ Typically, you generate docopt output to the standard output from the generated
315318
$ argbash my-script --type docopt --strip all
316319
317320
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
338+
$ rst2man my-script.rst > my-script.1
339+
$ man ./my-script.1
340+
341+
318342
.. _api_change:
319343

320344
API changes support

resources/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ EXAMPLES = \
5959
$(NUL)
6060

6161
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
62+
MANPAGE = argbash.1.gz
6263

6364
$(GENPARSE): ../src/argbash.m4 $(M4_SRC)
6465
ARGBASH_INTENDED_DESTINATION="$@" bash $(GENPARSE) $< -o argbash.temp && mv argbash.temp $@
@@ -146,7 +147,15 @@ define-version:
146147
$(eval VERSION_MAJOR := $(shell cut -f 1 -d . ../src/version))
147148
$(eval VERSION_SUFFIX := -$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH))
148149

149-
install: $(GENPARSE) $(A_INIT) $(ARGBASH_TO) $(COMPLETION)
150+
argbash.rst: ../src/argbash.m4 $(ARGBASH_EXEC)
151+
$(ARGBASH_EXEC) --type manpage --strip all -o $@ $<
152+
153+
man: $(MANPAGE)
154+
155+
$(MANPAGE): argbash.rst argbash-defs.rst
156+
rst2man $< | gzip > $@
157+
158+
install: $(GENPARSE) $(A_INIT) $(ARGBASH_TO) $(COMPLETION) $(MANPAGE)
150159
@echo Installing to prefix "'/$(PREFIX)' of root $(ROOT)"
151160
mkdir -p "$(ROOT)/$(PREFIX)/bin"
152161
touch "$(ROOT)/$(PREFIX)/bin/argbash$(VERSION_SUFFIX)"
@@ -158,6 +167,8 @@ install: $(GENPARSE) $(A_INIT) $(ARGBASH_TO) $(COMPLETION)
158167
cp -p $(A_INIT) "$(ROOT)/$(PREFIX)/bin/argbash-init$(VERSION_SUFFIX)" && chmod a+x "$(ROOT)/$(PREFIX)"/bin/argbash-init$(VERSION_SUFFIX)
159168
chmod a+x "$(ROOT)/$(PREFIX)/bin/argbash$(VERSION_SUFFIX)"
160169
test "$(INSTALL_COMPLETION)" = "no" || (mkdir -p "$(ROOT)/$(BASH_COMPLETION_DIRECTORY)" && mv "$(COMPLETION)" "$(ROOT)/$(BASH_COMPLETION_DIRECTORY)/")
170+
mkdir -p "$(ROOT)/$(PREFIX)/share/man/man1/"
171+
cp -p $(MANPAGE) "$(ROOT)/$(PREFIX)/share/man/man1/"
161172

162173
altpreclean: define-version
163174
$(RM) "$(ROOT)/$(PREFIX)/bin/argbash-$(VERSION_MAJOR).$(VERSION_MINOR)"
@@ -176,6 +187,7 @@ uninstall:
176187
$(RM) "$(ROOT)/$(PREFIX)"/bin/argbash-*
177188
rmdir "$(ROOT)/$(PREFIXED_LIBDIR)/argbash$(VERSION_SUFFIX)"
178189
$(RM) "$(ROOT)/$(BASH_COMPLETION_DIRECTORY)/$(COMPLETION)"
190+
$(RM) "$(ROOT)/$(PREFIX)/share/man/man1/$(MANPAGE)"
179191

180192
altuninstall: define-version uninstall
181193

@@ -199,4 +211,4 @@ tag:
199211

200212
# Update using
201213
# grep '^[-a-z]*:' Makefile | cut -f 1 -d ':' | sort | tr '\n' ' '
202-
.PHONY: altinstall altpreclean bootstrap check check-shellcheck define-version develop examples install release tag uninstall unittests version
214+
.PHONY: altinstall altpreclean bootstrap check check-shellcheck define-version develop examples install man release tag uninstall unittests version

resources/argbash-defs.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
.. |AUTHOR| replace:: Matěj Týč
3+
4+
.. |MAN_SECTION| replace:: 1
5+
6+
.. |DESCRIPTION| replace::
7+
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.
23+
24+
.. |OPTION_CHECK_TYPOS| replace:: \
25+
26+
.. |OPTION_COMMENTED| replace:: \
27+
28+
.. |OPTION_SEARCH| replace:: \
29+
30+
.. |OPTION_DEBUG| replace:: \
31+
32+
.. |OPTION_HELP| replace:: \
33+
34+
.. |OPTION_VERSION| replace:: \

src/output-manpage-defs.m4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ dnl $3: Padding of $2
3333
dnl $4: Help (optional)
3434
dnl $5: Default (optional)
3535
m4_define([_FORMAT_MANPAGE_OPTION], [m4_do(
36+
[_POSSIBLY_REPEATED_COMMENT_BLOCK([option], [], 0,
37+
m4_quote([.. You can have single-paragraph multi-line indented description instead of the '\']_ENDL_()))],
3638
[_FORMAT_REPLACEMENT([OPTION_]m4_toupper(m4_translit([[$1]], [-], [_])),
37-
[<Elaborate description], [of the option --$1], [or just leave there \ for no description]>.])],
39+
[\])],
3840
[_ENDL_()],
3941
)])
4042

@@ -45,6 +47,8 @@ dnl $2: Program description
4547
dnl $3: Program description 2
4648
m4_define([MAKE_RST_CONTENT], [m4_do(
4749
[_FORMAT_REPLACEMENT([AUTHOR], [<Your name goes here>])_ENDL_()],
50+
[_FORMAT_REPLACEMENT([VERSION], [\])_ENDL_()],
51+
[_FORMAT_REPLACEMENT([MAN_SECTION], [1])_ENDL_()],
4852
[_FORMAT_REPLACEMENT([DESCRIPTION], [<More elaborate description], [goes here>.])_ENDL_()],
4953
[MAKE_OPTIONS_SUMMARY([_FORMAT_MANPAGE_OPTION])],
5054
)])

src/output-manpage.m4

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ m4_define([ARGBASH_GO_BASE], [m4_do(
1616

1717
dnl
1818
dnl $1: date
19+
dnl $2: program name
1920
m4_define([_MAKE_METADATA], [[
2021
:Author: |AUTHOR|
2122
:Date: $1
22-
:Version: ]m4_ifdef([PROVIDED_VERSION_STRING], PROVIDED_VERSION_STRING, [[|VERSION|]])[
23-
:Manual section: 1
23+
:Version: ]m4_ifdef([PROVIDED_VERSION_STRING], m4_quote([$2 ]PROVIDED_VERSION_STRING), [[|VERSION|]])[
24+
:Manual section: |MAN_SECTION|
2425
]])
2526

2627

@@ -56,7 +57,7 @@ m4_define([MAKE_RST_CONTENT], [m4_do(
5657
[_ENDL_(2)],
5758
[UNDERLINE([$2], -, -)],
5859
[_ENDL_()],
59-
[_MAKE_METADATA(__today__)],
60+
[_MAKE_METADATA(__today__, [$1])],
6061
[_ENDL_(2)],
6162
[UNDERLINE([SYNOPSIS], =)],
6263
[_ENDL_(2)],

src/utilities.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ dnl Otherwise, act like _COMM_BLOCK
9898
m4_define([_POSSIBLY_REPEATED_COMMENT_BLOCK], [m4_ifndef([_COMMENT_$1_LOCATION], [m4_do(
9999
[m4_define([_COMMENT_$1_LOCATION], [[$2]])],
100100
[_COMM_BLOCK($3, m4_shiftn(3, $@))],
101-
)], [m4_do(
102-
[_COMM_BLOCK([$3], m4_quote([# ]m4_indir([_COMMENT_$1_LOCATION])))],
101+
)], [m4_do(m4_ifblank([$2], ,
102+
[_COMM_BLOCK([$3], m4_quote([# ]m4_indir([_COMMENT_$1_LOCATION])))]),
103103
)])])
104104
105105

0 commit comments

Comments
 (0)