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:

  1. Add kramdown-man ~> 1.0 to your Gemfile.
  2. mkdir man
  3. edit man/myprog.1.md. Use the example syntax as a guide.
  4. Add the Rake task to the Rakefile:
  5. rake man
  6. Add the resulting man/*.1 files to git or your gemspec’s files list.
  7. 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

Subtopics

Bookmarks

Questions