From 78a7dea3a0f9acedd4151749fe351a52eeb5fa12 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Fri, 26 Jun 2015 15:19:27 +0800 Subject: add `brew command` Closes Homebrew/homebrew#41034. Signed-off-by: Xu Cheng --- Library/Homebrew/cmd/command.rb | 14 ++++++++++++++ Library/Homebrew/global.rb | 17 +++++++++++++++++ Library/Homebrew/manpages/brew.1.md | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 Library/Homebrew/cmd/command.rb (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/cmd/command.rb b/Library/Homebrew/cmd/command.rb new file mode 100644 index 000000000..c2ea96dab --- /dev/null +++ b/Library/Homebrew/cmd/command.rb @@ -0,0 +1,14 @@ +module Homebrew + def command + cmd = ARGV.first + cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) + + if (path = HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb"; path.file?) + puts path + elsif (path = which("brew-#{cmd}") || which("brew-#{cmd}.rb")) + puts path + else + odie "Unknown command: #{cmd}" + end + end +end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index ba79f40d6..d9ec1a265 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -54,3 +54,20 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX = %r[https://github\.com/([\w-]+)/homebrew(-[\ require 'compat' unless ARGV.include? "--no-compat" or ENV['HOMEBREW_NO_COMPAT'] ORIGINAL_PATHS = ENV['PATH'].split(File::PATH_SEPARATOR).map{ |p| Pathname.new(p).expand_path rescue nil }.compact.freeze + +HOMEBREW_INTERNAL_COMMAND_ALIASES = { + 'ls' => 'list', + 'homepage' => 'home', + '-S' => 'search', + 'up' => 'update', + 'ln' => 'link', + 'instal' => 'install', # gem does the same + 'rm' => 'uninstall', + 'remove' => 'uninstall', + 'configure' => 'diy', + 'abv' => 'info', + 'dr' => 'doctor', + '--repo' => '--repository', + 'environment' => '--env', + '--config' => 'config', +} diff --git a/Library/Homebrew/manpages/brew.1.md b/Library/Homebrew/manpages/brew.1.md index 909b7448c..273228b4c 100644 --- a/Library/Homebrew/manpages/brew.1.md +++ b/Library/Homebrew/manpages/brew.1.md @@ -69,6 +69,9 @@ Note that these flags should only appear after a command. versions of formula. Note downloads for any installed formula will still not be deleted. If you want to delete those too: `rm -rf $(brew --cache)` + * `command` : + Display the path to the file which is used when invoking `brew `. + * `commands`: Show a list of built-in and external commands. -- cgit v1.2.3