Skip to content

Commit

Permalink
Fixed the manpage generation when program description is supplied.
Browse files Browse the repository at this point in the history
Fixes: #78
  • Loading branch information
matejak committed May 12, 2019
1 parent a4344d9 commit 6316199
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Bugfixes:

* The environment variables help message has been fixed (#79).
* The manpage generation works when long description is supplied (#78).


2.8.0 (2019-01-26)
Expand Down
4 changes: 3 additions & 1 deletion src/docopt.m4
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ dnl $2: Long + short
dnl $3: Padding of $2
dnl $4: Help (optional)
dnl $5: Default (optional)
dnl
dnl 2 + 2 in the substitute function: 2 leading spaces + 2 spaces between options and text.
m4_define([_FORMAT_DOCOPT_OPTION], [m4_do(
[m4_format([[ %-$3s]]m4_ifnblank([$4$5], [[[ %s]]])m4_ifnblank([$5], [[[ [default: %s]]]])._ENDL_(), [$2], [$4], [$5])],
[m4_format([[ %-$3s]]m4_ifnblank([$4$5], [[[ %s]]])m4_ifnblank([$5], [[[ [default: %s]]]])._ENDL_(), [$2], _SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES([$4], m4_eval([$3] + 2 + 2)), [$5])],
)])


Expand Down
9 changes: 3 additions & 6 deletions src/output-manpage.m4
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dnl $4: Help (optional)
dnl $5: Default (optional)
m4_define([_FORMAT_MANPAGE_OPTION], [m4_do(
[m4_format([[%-$3s]]m4_ifnblank([$4$5], [[[ %s.]]])m4_ifnblank([$5], [_ENDL_()[[%-$3s %s]]])_ENDL_(2)[[%-$3s %s]],
[$2], [$4], m4_ifnblank([$5], [[ ], [[Default: $5]],]) [ ], m4_quote(|[OPTION_]m4_toupper(m4_translit([[$1]], [-], [_]))|))],
[$2], _SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES([$4], m4_eval([$3] + 2)), m4_ifnblank([$5], [[ ], [[Default: $5]],]) [ ], m4_quote(|[OPTION_]m4_toupper(m4_translit([[$1]], [-], [_]))|))],
[_ENDL_(2)],
)])

Expand All @@ -61,13 +61,10 @@ m4_define([MAKE_RST_CONTENT], [m4_do(
[_ENDL_(2)],
[UNDERLINE([SYNOPSIS], =)],
[_ENDL_(2)],
[``$1 _MAKE_HELP_SYNOPSIS()``],
[``[$1] _MAKE_HELP_SYNOPSIS()``],
[_ENDL_(3)],
[UNDERLINE([DESCRIPTION], =)],
[m4_ifnblank([$3], [m4_dquote_elt(
[_ENDL_(2)],
[$3],
)])],
m4_ifnblank([$3], [[_ENDL_(2)],[[$3]]]),
[_ENDL_(2)],
[|DESCRIPTION|],
[_ENDL_(3)],
Expand Down
12 changes: 10 additions & 2 deletions src/utilities.m4
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ m4_define([_COMMENT], [m4_ifdef([COMMENT_OUTPUT], [$1])])
dnl
dnl $1: The text to substitute
dnl Regexp: Find beginning of backslashes, match for pairs, and if \\n is left, then substitute it for literal newline.
dnl The indentation is a display indentation - not source code one.
m4_define([_SUBSTITUTE_LF_FOR_NEWLINE_WITH_DISPLAY_INDENT_AND_ESCAPE_DOUBLEQUOTES],
[SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([$1], [ ])])
dnl
dnl $1: The text to substitute
dnl $2: The width of space indentation
dnl The indentation is a display indentation - not source code one.
m4_define([_SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES],
[SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([$1], m4_if([$2], 0, [], [m4_for(_, 1, [$2], 1, [ ])]))])
dnl
dnl $1: The text to substitute
dnl $2: The indent for the new line.
Expand Down Expand Up @@ -298,7 +306,7 @@ m4_define([UNDERLINE], [m4_do(
[m4_for(idx, 1, m4_len([$1]), 1, [$3])],
[_ENDL_()],
)])])],
[$1],
[[$1]],
[_ENDL_()],
[m4_if(m4_len([$1]), 0, ,
[m4_for(idx, 1, m4_len([$1]), 1, [$2])])],
Expand Down
3 changes: 2 additions & 1 deletion tests/regressiontests/test-simple.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# ARG_POSITIONAL_SINGLE([pos-arg], [help line PEND-\n-PBEGIN])
# ARG_OPTIONAL_SINGLE([prefix],[o],[help line END-\n-BEGIN "line 2" END-\\n-2BEGIN],[x])
# ARG_OPTIONAL_SINGLE([la], [l], [help line END-\n-BEGIN "line 2"])
# ARG_VERSION([echo "$0 FOO"])
# ARG_HELP([Testing program m4_fatal(BOOM!)], [m4_fatal([CRASH!])])
# ARG_DEFAULTS_POS()
Expand All @@ -11,7 +12,7 @@

# Now we take the parsed data and assign them no nice-looking variable names,
# sometimes after a basic validation
echo "OPT_S=$_arg_prefix,POS_S=$_arg_pos_arg,"
echo "OPT_S=$_arg_prefix,POS_S=$_arg_pos_arg,LA=$_arg_la,"

# ] <-- needed because of Argbash
m4_ifdef([m4_esyscmd], [m4_fatal([The m4_esyscmd macro is enabled!])])
14 changes: 13 additions & 1 deletion tests/unittests/check-utils.m4
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,22 @@ assert_equals(UNDERLINE(,=,=), [
assert_equals(UNDERLINE([a], [-]), [a
-])

assert_equals(SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([The Castle\n"Totenhammer"], [-]), [The Castle
assert_equals(UNDERLINE([BOMB], [-]), [BOMB
----])

assert_equals(SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([BOMB Castle\n"Totenhammer"], [-]), [BOMB Castle
-\"Totenhammer\"])


assert_equals(_SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES([The Castle\n"Totenhammer"], [0]), [The Castle
\"Totenhammer\"])

assert_equals(_SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES([The Castle\n"Totenhammer"], [1]), [The Castle
\"Totenhammer\"])

assert_equals(_SUBSTITUTE_LF_FOR_NEWLINE_WITH_SPACE_INDENT_AND_ESCAPE_DOUBLEQUOTES([The Castle\n"Totenhammer"], [2]), [The Castle
\"Totenhammer\"])

assert_equals(UNDERLINE([Abc], [+], [=]), [===
Abc
+++])

0 comments on commit 6316199

Please sign in to comment.