2016-09-10 10:24:56 +01:00
|
|
|
HOMEBREW_HELP = <<-EOS.freeze
|
2011-03-13 12:54:30 +00:00
|
|
|
Example usage:
|
2016-05-01 15:22:55 +02:00
|
|
|
brew search [TEXT|/REGEX/]
|
2016-04-19 03:17:45 +02:00
|
|
|
brew (info|home|options) [FORMULA...]
|
2011-03-13 12:54:30 +00:00
|
|
|
brew install FORMULA...
|
|
|
|
brew update
|
2015-08-07 19:36:29 +08:00
|
|
|
brew upgrade [FORMULA...]
|
2016-05-01 15:22:55 +02:00
|
|
|
brew uninstall FORMULA...
|
|
|
|
brew list [FORMULA...]
|
2011-03-13 12:54:30 +00:00
|
|
|
|
|
|
|
Troubleshooting:
|
2016-05-01 15:22:55 +02:00
|
|
|
brew config
|
2011-03-13 12:54:30 +00:00
|
|
|
brew doctor
|
|
|
|
brew install -vd FORMULA
|
|
|
|
|
2016-09-08 20:48:38 +01:00
|
|
|
Developers:
|
2011-03-13 12:54:30 +00:00
|
|
|
brew create [URL [--no-fetch]]
|
|
|
|
brew edit [FORMULA...]
|
2016-04-03 14:03:33 +01:00
|
|
|
https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Formula-Cookbook.md
|
2011-03-13 12:54:30 +00:00
|
|
|
|
|
|
|
Further help:
|
|
|
|
man brew
|
2016-04-19 03:17:45 +02:00
|
|
|
brew help [COMMAND]
|
2011-03-13 12:54:30 +00:00
|
|
|
brew home
|
|
|
|
EOS
|
|
|
|
|
|
|
|
# NOTE Keep the lenth of vanilla --help less than 25 lines!
|
|
|
|
# This is because the default Terminal height is 25 lines. Scrolling sucks
|
|
|
|
# and concision is important. If more help is needed we should start
|
|
|
|
# specialising help like the gem command does.
|
|
|
|
# NOTE Keep lines less than 80 characters! Wrapping is just not cricket.
|
|
|
|
# NOTE The reason the string is at the top is so 25 lines is easy to measure!
|
|
|
|
|
2016-09-07 20:09:29 +01:00
|
|
|
require "commands"
|
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-04-19 07:24:21 +02:00
|
|
|
def help(cmd = nil, flags = {})
|
|
|
|
# Resolve command aliases and find file containing the implementation.
|
|
|
|
if cmd
|
|
|
|
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
2016-09-07 20:09:29 +01:00
|
|
|
path = Commands.path(cmd)
|
2016-04-19 07:24:21 +02:00
|
|
|
end
|
|
|
|
|
2016-04-19 07:33:13 +02:00
|
|
|
# Display command-specific (or generic) help in response to `UsageError`.
|
|
|
|
if (error_message = flags[:usage_error])
|
|
|
|
$stderr.puts path ? command_help(path) : HOMEBREW_HELP
|
|
|
|
$stderr.puts
|
|
|
|
onoe error_message
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2016-04-17 03:45:10 +02:00
|
|
|
# Handle `brew` (no arguments).
|
2016-04-19 07:24:21 +02:00
|
|
|
if flags[:empty_argv]
|
2016-04-17 03:45:10 +02:00
|
|
|
$stderr.puts HOMEBREW_HELP
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Handle `brew (-h|--help|--usage|-?|help)` (no other arguments).
|
|
|
|
if cmd.nil?
|
|
|
|
puts HOMEBREW_HELP
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
2016-04-19 07:24:21 +02:00
|
|
|
# Resume execution in `brew.rb` for external/unknown commands.
|
|
|
|
return if path.nil?
|
2016-04-17 03:45:10 +02:00
|
|
|
|
|
|
|
# Display help for internal command (or generic help if undocumented).
|
2016-04-19 07:24:21 +02:00
|
|
|
puts command_help(path)
|
2016-04-17 03:45:10 +02:00
|
|
|
exit 0
|
2011-03-13 12:54:30 +00:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
|
2016-04-17 03:45:10 +02:00
|
|
|
private
|
|
|
|
|
2016-04-19 07:24:21 +02:00
|
|
|
def command_help(path)
|
|
|
|
help_lines = path.read.lines.grep(/^#:/)
|
|
|
|
if help_lines.empty?
|
|
|
|
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
|
|
|
|
HOMEBREW_HELP
|
|
|
|
else
|
|
|
|
help_lines.map do |line|
|
2016-09-10 10:24:56 +01:00
|
|
|
line.slice(2..-1)
|
|
|
|
.sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ")
|
|
|
|
.gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}")
|
|
|
|
.gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}")
|
|
|
|
.gsub("@hide_from_man_page", "")
|
2016-06-28 08:08:12 -07:00
|
|
|
end.join.strip
|
2016-04-19 07:24:21 +02:00
|
|
|
end
|
2016-04-03 20:17:01 +02:00
|
|
|
end
|
2011-03-13 12:54:30 +00:00
|
|
|
end
|