diff options
| author | Max Nordlund | 2016-04-03 20:17:01 +0200 |
|---|---|---|
| committer | Martin Afanasjew | 2016-04-10 22:59:24 +0200 |
| commit | b21f699ff2f1691c4f10422c640a9d392cf2d7a7 (patch) | |
| tree | e1ddc0886da402bff7bcb0bbef2c9620949929d4 /Library/Homebrew/cmd/man.rb | |
| parent | 32ae71b256089b4f34365eb969a3c8aa3bce52dd (diff) | |
| download | brew-b21f699ff2f1691c4f10422c640a9d392cf2d7a7.tar.bz2 | |
Implement the `brew help` command
This is also used by `brew <cmd> --help`. The basic idea is to have the
documentation as a top level comment in each command file. To find these
comments, they have to be like this `#:`.
This is also used by the `brew man` command to keep the documentation
DRY, and for that there are now a header and footer for the man page.
Diffstat (limited to 'Library/Homebrew/cmd/man.rb')
| -rw-r--r-- | Library/Homebrew/cmd/man.rb | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/Library/Homebrew/cmd/man.rb b/Library/Homebrew/cmd/man.rb index a3f95f53f..785e2cf65 100644 --- a/Library/Homebrew/cmd/man.rb +++ b/Library/Homebrew/cmd/man.rb @@ -25,21 +25,35 @@ module Homebrew puts "Writing HTML fragments to #{DOC_PATH}" puts "Writing manpages to #{TARGET_PATH}" - Dir["#{SOURCE_PATH}/*.md"].each do |source_file| - args = %W[ - --pipe - --organization=Homebrew - --manual=brew - #{source_file} - ] - page = File.basename(source_file, ".md") - - target_html = DOC_PATH/"#{page}.html" - target_html.atomic_write Utils.popen_read("ronn", "--fragment", *args) - - target_man = TARGET_PATH/page - target_man.atomic_write Utils.popen_read("ronn", "--roff", *args) - end + header = (SOURCE_PATH/"header.1.md").read + footer = (SOURCE_PATH/"footer.1.md").read + sub_commands = Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/cmd/*.{rb,sh}"). + sort_by { |source_file| source_file.basename.sub(/\.(rb|sh)$/, "") }. + map { |source_file| + source_file.read. + split("\n"). + grep(/^#:/). + map { |line| line.slice(2..-1) }. + join("\n") + }. + reject { |s| s.strip.empty? }. + join("\n\n") + + target_md = SOURCE_PATH/"brew.1.md" + target_md.atomic_write(header + sub_commands + footer) + + args = %W[ + --pipe + --organization=Homebrew + --manual=brew + #{SOURCE_PATH}/brew.1.md + ] + + target_html = DOC_PATH/"brew.1.html" + target_html.atomic_write Utils.popen_read("ronn", "--fragment", *args) + + target_man = TARGET_PATH/"brew.1" + target_man.atomic_write Utils.popen_read("ronn", "--roff", *args) end end end |
