aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/help.rb
diff options
context:
space:
mode:
authorMax Nordlund2016-04-03 20:17:01 +0200
committerMartin Afanasjew2016-04-10 22:59:24 +0200
commitb21f699ff2f1691c4f10422c640a9d392cf2d7a7 (patch)
treee1ddc0886da402bff7bcb0bbef2c9620949929d4 /Library/Homebrew/cmd/help.rb
parent32ae71b256089b4f34365eb969a3c8aa3bce52dd (diff)
downloadbrew-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/help.rb')
-rw-r--r--Library/Homebrew/cmd/help.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb
index f729c0e8c..76eef90a8 100644
--- a/Library/Homebrew/cmd/help.rb
+++ b/Library/Homebrew/cmd/help.rb
@@ -39,4 +39,23 @@ module Homebrew
def help_s
HOMEBREW_HELP
end
+
+ def help_for_command(cmd)
+ cmd_path = if File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh")
+ HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh"
+ elsif ARGV.homebrew_developer? && File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh")
+ HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh"
+ elsif File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb")
+ HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb"
+ elsif ARGV.homebrew_developer? && File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb")
+ HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb"
+ end
+ return if cmd_path.nil?
+
+ cmd_path.read.
+ split("\n").
+ grep(/^#:/).
+ map { |line| line.slice(2..-1).delete("`").sub(/^ \* /, "brew ") }.
+ join("\n")
+ end
end