aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cmd/help.rb19
-rw-r--r--Library/Homebrew/cmd/man.rb44
-rw-r--r--Library/Homebrew/cmd/update.sh3
-rw-r--r--Library/brew.rb26
-rw-r--r--Library/brew.sh4
5 files changed, 70 insertions, 26 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
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
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index 8ffd2eadb..2c04664c3 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -220,8 +220,7 @@ homebrew-update() {
for option in "$@"
do
case "$option" in
- # TODO: - `brew update --help` should display update subcommand help
- --help) brew --help; exit $? ;;
+ --help) brew help update; exit $? ;;
--verbose) HOMEBREW_VERBOSE=1 ;;
--debug) HOMEBREW_DEBUG=1;;
--rebase) HOMEBREW_REBASE=1 ;;
diff --git a/Library/brew.rb b/Library/brew.rb
index 4b789a490..4c7cc8d65 100644
--- a/Library/brew.rb
+++ b/Library/brew.rb
@@ -69,15 +69,27 @@ begin
# It should never affect external commands so they can handle usage
# arguments themselves.
- if empty_argv || (help_flag && (cmd.nil? || internal_cmd))
- # TODO: - `brew help cmd` should display subcommand help
- require "cmd/help"
- if empty_argv
- $stderr.puts ARGV.usage
- else
+ if empty_argv
+ $stderr.puts ARGV.usage
+ exit 1
+ elsif help_flag
+ if cmd.nil?
puts ARGV.usage
+ exit 0
+ else
+ # Handle both internal ruby and shell commands
+ require "cmd/help"
+ help_text = Homebrew.help_for_command(cmd)
+ if help_text.nil?
+ # External command, let it handle help by itself
+ elsif help_text.empty?
+ puts "No help available for #{cmd}"
+ exit 1
+ else
+ puts help_text
+ exit 0
+ end
end
- exit ARGV.any? ? 0 : 1
end
if internal_cmd
diff --git a/Library/brew.sh b/Library/brew.sh
index c52b8f966..7f9d141cf 100644
--- a/Library/brew.sh
+++ b/Library/brew.sh
@@ -176,9 +176,9 @@ case "$HOMEBREW_COMMAND" in
--config) HOMEBREW_COMMAND="config";;
esac
-if [[ -f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" ]] ; then
+if [[ -f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" ]]; then
HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh"
-elif [[ -n "$HOMEBREW_DEVELOPER" && -f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]] ; then
+elif [[ -n "$HOMEBREW_DEVELOPER" && -f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]]; then
HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh"
fi