diff options
| author | Mike McQuaid | 2014-06-25 09:45:01 +0100 | 
|---|---|---|
| committer | Mike McQuaid | 2014-06-26 08:37:25 +0100 | 
| commit | 8cae4ac478721ff93d2e8fac553997885528db87 (patch) | |
| tree | 1ec8e01545e5f88e8338eed28fea327fe208c2b7 | |
| parent | 17793969f1fdc6a871ebcdb232e34851633dbd73 (diff) | |
| download | homebrew-8cae4ac478721ff93d2e8fac553997885528db87.tar.bz2 | |
brew.rb: handle -—help for internal/external cmds.
Only display —-help for internal commands and not for external ones;
they can handle the flag themselves.
Closes #26675.
References #26755.
Closes #30300.
| -rwxr-xr-x | Library/brew.rb | 42 | 
1 files changed, 33 insertions, 9 deletions
| diff --git a/Library/brew.rb b/Library/brew.rb index 9064cacdb..e2f2f153e 100755 --- a/Library/brew.rb +++ b/Library/brew.rb @@ -15,12 +15,7 @@ HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Lib  $:.unshift(HOMEBREW_LIBRARY_PATH.to_s)  require 'global' -if ARGV.empty? || ARGV[0] =~ /(-h$|--help$|--usage$|-\?$|help$)/ -  # TODO - `brew help cmd` should display subcommand help -  require 'cmd/help' -  puts ARGV.usage -  exit ARGV.any? ? 0 : 1 -elsif ARGV.first == '--version' +if ARGV.first == '--version'    puts HOMEBREW_VERSION    exit 0  elsif ARGV.first == '-v' @@ -60,7 +55,6 @@ end  # odd exceptions. Reduce our support burden by showing a user-friendly error.  Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed." -  def require? path    require path  rescue LoadError => e @@ -88,7 +82,21 @@ begin               '--config' => 'config',               } -  cmd = ARGV.shift +  empty_argv = ARGV.empty? +  help_regex = /(-h$|--help$|--usage$|-\?$|help$)/ +  help_flag = false +  cmd = nil + +  ARGV.dup.each_with_index do |arg, i| +    if help_flag && cmd +      break +    elsif arg =~ help_regex +      help_flag = true +    elsif !cmd +      cmd = ARGV.delete_at(i) +    end +  end +    cmd = aliases[cmd] if aliases[cmd]    sudo_check = Set.new %w[ install link pin unpin upgrade ] @@ -102,7 +110,23 @@ begin    # Add contributed commands to PATH before checking.    ENV['PATH'] += "#{File::PATH_SEPARATOR}#{HOMEBREW_CONTRIB}/cmd" -  if require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) +  internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) + +  # Usage instructions should be displayed if and only if one of: +  # - a help flag is passed AND an internal command is matched +  # - no arguments are passed +  # +  # It should never affect external commands so they can handle usage +  # arguments themselves. + +  if empty_argv || (internal_cmd && help_flag) +    # TODO - `brew help cmd` should display subcommand help +    require 'cmd/help' +    puts ARGV.usage +    exit ARGV.any? ? 0 : 1 +  end + +  if internal_cmd      Homebrew.send cmd.to_s.gsub('-', '_').downcase    elsif which "brew-#{cmd}"      %w[CACHE CELLAR LIBRARY_PATH PREFIX REPOSITORY].each do |e| | 
