Skip to content

Commit

Permalink
Add options to command reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Gunderloy authored and Mike Gunderloy committed Jan 10, 2012
1 parent ae82489 commit 164f34d
Show file tree
Hide file tree
Showing 3 changed files with 680 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ task :command_guide do
htmlify("* #{string}")
end

def options_list(command)
# Invoke the Ruby options parser by asking for help. Otherwise the options
# list in the parser will never be initialized.
# TODO: Figure out how to avoid dumping help to stdout when running this rake task
command.show_help
parser = command.send(:parser)
options = ''
helplines = parser.summarize
helplines.each do |helpline|
break if (helpline =~ /Arguments/) || (helpline =~ /Summary/)
unless helpline.gsub(/\n/, '').strip == ''
# Use zero-width space to prevent "helpful" change of -- to –
helpline = helpline.gsub('--', '-​-')
if helpline =~ /^\s{10,}(.*)/
options = options[0..-2] + " #{$1}\n"
else
if helpline =~ /^(.*)\s{3,}(.*)/
helpline = "#{$1} - #{$2}"
end
if helpline =~ /options/i
options += "\n### #{helpline}\n"
else
options += "* #{helpline}\n"
end
end
end
end
options
end

erbio = RDoc::ERBIO.new File.read("command-reference.erb"), nil, nil
open 'command-reference.md', 'w' do |io|
erbio.result binding
Expand Down
2 changes: 2 additions & 0 deletions command-reference.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ What each `gem` command does, and how to use it.

<%= command.usage %> [options]

<%= options_list(command) %>
<% if command.arguments != "" %>
### Arguments

Expand Down
Loading

0 comments on commit 164f34d

Please sign in to comment.