Add man pages to your Ruby CLI
Topics: Ruby
A Ruby command-line tool can open a generated man page from its --help option.
How to add man pages to your Ruby CLI:
- Add
kramdown-man ~> 1.0to yourGemfile. mkdir man- edit
man/myprog.1.md. Use the example syntax as a guide. - Add the Rake task to the
Rakefile: rake man- Add the resulting
man/*.1files to git or yourgemspec’s files list. - Add this code to your CLI’s
--help:
MAN_PAGE = '../man/myprog.1'
opts.on('-h','--help') do
if $stdout.tty?
system('man',MAN_PAGE)
else
puts opts
end
end