Skip to content

Commit 1f6a706

Browse files
committed
improve manpage template
1 parent d225d41 commit 1f6a706

File tree

13 files changed

+104
-19
lines changed

13 files changed

+104
-19
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ RSpec/FilePath:
2828
- 'spec/bashly/concerns/completions_command_spec.rb'
2929
- 'spec/bashly/concerns/completions_flag_spec.rb'
3030

31+
# FIXME: This test is ugly and long
32+
RSpec/ExampleLength:
33+
Exclude:
34+
- 'spec/bashly/integration/rendering_spec.rb'

lib/bashly/extensions/string.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ def for_markdown
77
gsub('<', '\\<').gsub('>', '\\>').nl2br
88
end
99

10+
def for_manpage
11+
gsub('<', '\\<').gsub('>', '\\>').gsub('`', '**').gsub("\n", "\n\n")
12+
end
13+
1014
def nl2br
1115
gsub("\n", " \n")
1216
end
@@ -21,6 +25,10 @@ def to_underscore
2125
gsub(/(.)([A-Z])/, '\1_\2').gsub(/[- ]/, '_').downcase
2226
end
2327

28+
def to_hyphen
29+
tr(' ', '-').gsub(/([a-z])([A-Z])/, '\1-\2').downcase
30+
end
31+
2432
def to_path
2533
tr(' ', '/').downcase
2634
end

lib/bashly/libraries/render/mandoc/mandoc.gtx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Reference: https://linux.die.net/man/5/pandoc_markdown
22

33
if version
4-
> % {{ full_name.tr(' ', '-') }}(1) Version {{ version }} | {{ summary }}
4+
> % {{ full_name.to_hyphen }}(1) Version {{ version }} | {{ summary }}
55
else
6-
> % {{ full_name.tr(' ', '-') }}(1) | {{ summary }}
6+
> % {{ full_name.to_hyphen }}(1) | {{ summary }}
77
end
88
> % {{ ENV['AUTHORS'] }}
99
> % {{ Date.today.strftime "%B %Y" }}
@@ -24,7 +24,7 @@ end
2424
> DESCRIPTION
2525
> ==================================================
2626
>
27-
> {{ help.for_markdown }}
27+
> {{ help.for_manpage }}
2828
>
2929

3030
if default
@@ -42,14 +42,14 @@ if extensible
4242
end
4343
>
4444

45-
if commands.any?
45+
if public_commands.any?
4646
grouped_commands.each do |group, commands|
4747
> {{ group.gsub(/:$/, '').upcase }}
4848
> ==================================================
4949
>
5050
commands.each do |subcommand|
5151
> **{{ subcommand.full_name }}**(1)
52-
> : {{ subcommand.summary.for_markdown }}
52+
> : {{ subcommand.summary.for_manpage }}
5353
>
5454
end
5555
>
@@ -62,7 +62,7 @@ if args.any?
6262
>
6363
args.each do |arg|
6464
> **{{ arg.name.upcase }}**
65-
> : {{ arg.help.for_markdown }}
65+
> :{{ arg.help.for_manpage.indent(4) }}
6666
>
6767
if arg.required
6868
> - *Required*
@@ -81,7 +81,10 @@ if args.any?
8181

8282
if catch_all.label && catch_all.help
8383
> **{{ catch_all.label }}**
84-
> : {{ catch_all.help&.for_markdown }}
84+
if catch_all.help
85+
> :{{ catch_all.help.for_manpage.indent(4) }}
86+
>
87+
end
8588
>
8689

8790
if catch_all.required?
@@ -97,7 +100,7 @@ if flags.any?
97100
>
98101
flags.each do |flag|
99102
> **{{ flag.usage_string }}**
100-
> : {{ flag.help.for_markdown }}
103+
> :{{ flag.help.for_manpage.indent(4) }}
101104
>
102105

103106
if flag.required
@@ -125,8 +128,10 @@ if dependencies.any?
125128
>
126129
dependencies.each do |dependency|
127130
> **{{ dependency.commands.join ', ' }}**
128-
>
129-
> :{{ dependency.help&.indent(4)&.for_markdown }}
131+
if dependency.help
132+
> :{{ dependency.help.for_manpage.indent(4) }}
133+
>
134+
end
130135
>
131136
end
132137
end
@@ -138,7 +143,7 @@ if public_environment_variables.any?
138143
public_environment_variables.each do |environment_variable|
139144
> **{{ environment_variable.name.upcase }}**
140145
>
141-
> :{{ environment_variable.help.indent(4).for_markdown }}
146+
> :{{ environment_variable.help.for_manpage.indent(4) }}
142147
>
143148

144149
if environment_variable.required
@@ -157,10 +162,16 @@ if examples
157162
>
158163
> ~~~
159164
examples.each do |example|
160-
> {{ example.for_markdown }}
165+
> {{ example.for_manpage }}
161166
>
162167
end
163168
> ~~~
164169
end
165170

166-
171+
if public_commands.any?
172+
> SEE ALSO
173+
> ==================================================
174+
>
175+
= public_commands.map { |x| "**#{x.full_name.to_hyphen}**(1)" }.join ', '
176+
>
177+
end

lib/bashly/libraries/render/mandoc/render.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
save mdfile, gtx.parse(command)
1212

1313
cmd = %[pandoc -f markdown-smart -s --to man "#{mdfile}" > "#{manfile}"]
14-
15-
success = system "#{cmd}"
14+
15+
success = system cmd
1616
raise "Failed running pandoc\nMake sure the following command succeeds and try again:\n\n #{cmd}" unless success
1717

1818
say "g`saved` #{manfile}"

spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ARGUMENTS
3434
**AWS PARAMS...**
3535
: Additional arguments or flags for AWS CLI
3636

37+
3738
OPTIONS
3839
==================================================
3940

spec/approvals/rendering/mandoc/catch-all-advanced/cli.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ COMMANDS
2828
: Upload a file
2929

3030

31+
SEE ALSO
32+
==================================================
33+
34+
**cli-download**(1), **cli-upload**(1)
35+

spec/approvals/rendering/mandoc/dependencies-alt/cli-download.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ DEPENDENCIES
2323

2424
**git**
2525

26-
:
27-
2826
**ruby**
29-
3027
: visit $(blue_underlined https://www.ruby-lang.org) to install
3128

32-
**curl, wget**
3329

30+
**curl, wget**
3431
: install with $(green sudo apt install curl)
3532

33+

spec/approvals/rendering/mandoc/dependencies-alt/cli.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ COMMANDS
2525
: Download something
2626

2727

28+
SEE ALSO
29+
==================================================
30+
31+
**cli-download**(1)
32+

spec/approvals/rendering/mandoc/docker-like/docker-container.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ COMMANDS
2929
: Stop a container
3030

3131

32+
SEE ALSO
33+
==================================================
34+
35+
**docker-container-run**(1), **docker-container-stop**(1)
36+

spec/approvals/rendering/mandoc/docker-like/docker-image.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ COMMANDS
2626
: Show all images
2727

2828

29+
SEE ALSO
30+
==================================================
31+
32+
**docker-image-ls**(1)
33+

0 commit comments

Comments
 (0)