Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 130 lines (114 sloc) 3.699 kB
84bf873 @mxcl Don't output Ruby warnings
mxcl authored
1 #!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
b539e96 @bmaland Sort the output from `brew install`
bmaland authored
2 # -*- coding: utf-8 -*-
725a699 @imbriaco Fix brew if it's symlinked from elsewhere
imbriaco authored
3
b1dc038 @mxcl Much better CTRL-C handling
mxcl authored
4 std_trap = trap("INT") { exit! 130 } # no backtrace thanks
5
d81a8e6 @mxcl Simplify the library path determination code a little
mxcl authored
6 HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] = File.expand_path(__FILE__)
ce01313 @adamv Rewrite of HOMEBREW_ folder locations
adamv authored
7
cf59297 @mxcl Make `brew --prefix` very fast
mxcl authored
8 if ARGV == %w{--prefix}
9 puts File.dirname(File.dirname(HOMEBREW_BREW_FILE))
10 exit 0
11 end
12
d81a8e6 @mxcl Simplify the library path determination code a little
mxcl authored
13 require 'pathname'
5cd927b @mxcl Some Cleanup
mxcl authored
14 HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library/Homebrew").to_s
9e773c3 @Sharpie metadata: Record installation options
Sharpie authored
15 $:.unshift(HOMEBREW_LIBRARY_PATH + '/vendor')
b5d132e @mxcl We can't rely on the $: order
mxcl authored
16 $:.unshift(HOMEBREW_LIBRARY_PATH)
2b22c47 @mxcl Allow formulae to use __END__
mxcl authored
17 require 'global'
6b6d369 @mxcl Refactor
mxcl authored
18
7fafb50 @mxcl `brew` by itself prints help but exits with non-zero
mxcl authored
19 case ARGV.first when '-h', '--help', '--usage', '-?', 'help', nil
20 require 'cmd/help'
21 puts Homebrew.help_s
22 exit ARGV.first ? 0 : 1
629c4e3 @mxcl Handle certain ARGV parameters before certain error checks
mxcl authored
23 when '--version'
24 puts HOMEBREW_VERSION
25 exit 0
26 when '-v'
7e03409 @adamv Make --version/--verbose slightly less confusing.
adamv authored
27 puts "Homebrew #{HOMEBREW_VERSION}"
28 # Shift the -v to the end of the parameter list
29 ARGV << ARGV.shift
30 # If no other arguments, just quit here.
31 exit 0 if ARGV.length == 1
629c4e3 @mxcl Handle certain ARGV parameters before certain error checks
mxcl authored
32 end
33
34 case HOMEBREW_PREFIX.to_s when '/', '/usr'
35 # it may work, but I only see pain this route and don't want to support it
36 abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}"
d614113 @mxcl Refactor Formulae
mxcl authored
37 end
9c16145 @mikemcquaid Set MACOS_VERSION as 0 on non-OSX platforms.
mikemcquaid authored
38 if MACOS and MACOS_VERSION < 10.5
5cd927b @mxcl Some Cleanup
mxcl authored
39 abort <<-EOABORT.undent
40 Homebrew requires Leopard or higher. For Tiger support, see:
41 http://github.com/sceaga/homebrew/tree/tiger
42 EOABORT
ed1fed4 @mxcl Error out if the host OS X is too old
mxcl authored
43 end
68108e1 @mxcl Dependency resolution with fancy syntax
mxcl authored
44
53f83cc @mxcl Move the Dir.getwd after help
mxcl authored
45 # Many Pathname operations use getwd when they shouldn't, and then throw
46 # odd exceptions. Reduce our support burden by showing a user-friendly error.
47 Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed."
48
49
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
50 def require? path
51 require path.to_s.chomp
52 rescue LoadError => e
53 # HACK :( because we should raise on syntax errors but
54 # not if the file doesn't exist. TODO make robust!
55 raise unless e.to_s.include? path
ce01313 @adamv Rewrite of HOMEBREW_ folder locations
adamv authored
56 end
57
d614113 @mxcl Refactor Formulae
mxcl authored
58 begin
b1dc038 @mxcl Much better CTRL-C handling
mxcl authored
59 trap("INT", std_trap) # restore default CTRL-C handler
60
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
61 aliases = {'ls' => :list,
62 'homepage' => :home,
63 '-S' => :search,
64 'up' => :update,
65 'ln' => :link,
28d0d16 Support the `brew instal` typo
Max Howell authored
66 'instal' => :install, # gem does the same
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
67 'rm' => :uninstall,
68 'remove' => :uninstall,
69 'configure' => :diy,
70 'abv' => :info,
71 'dr' => :doctor,
f828347 @mxcl brew environment alias to --env; like `gem`
mxcl authored
72 '--repo' => '--repository',
73 'environment' => '--env' # same as gem
74 }
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
75
76 cmd = ARGV.shift
77 cmd = aliases[cmd] if aliases[cmd]
78
a8fadbf @mxcl `brew -c1` one line configuration summary
mxcl authored
79 if cmd == '-c1'
80 cmd = '--config'
81 ARGV.unshift('-1')
82 end
83
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
84 # Add example external commands to PATH before checking.
b27b761 @mikemcquaid Rename external commands directory from examples.
mikemcquaid authored
85 ENV['PATH'] += ":#{HOMEBREW_REPOSITORY}/Library/Contributions/cmds"
76604c1 @jacknagel Unify 'which' and which_s' utility methods
jacknagel authored
86 if which "brew-#{cmd}"
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
87 %w[CACHE CELLAR LIBRARY_PATH PREFIX REPOSITORY].each do |e|
eb121ee @eregon use Module#const_get instead of eval
eregon authored
88 ENV["HOMEBREW_#{e}"] = Object.const_get "HOMEBREW_#{e}"
9cf6840 @mxcl brew outdated
mxcl authored
89 end
9afc85a @mxcl Refactor the brew command into one file per command
mxcl authored
90 exec "brew-#{cmd}", *ARGV
91 elsif require? `/usr/bin/which brew-#{cmd}.rb`
92 exit 0
93 elsif require? HOMEBREW_REPOSITORY/"Library/Homebrew/cmd"/cmd
ef27207 @mistydemeo brew: downcase arg before sending to Homebrew
mistydemeo authored
94 Homebrew.send cmd.to_s.gsub('-', '_').downcase
f2a6979 @mxcl brew log command
mxcl authored
95 else
1f774a8 @adamv Remove 'is this a git command?'
adamv authored
96 onoe "Unknown command: #{cmd}"
97 exit 1
d614113 @mxcl Refactor Formulae
mxcl authored
98 end
2a5a754 @mxcl brew prefix command
mxcl authored
99
1b066d7 @mxcl Better errors if missing keg or formula arguments
mxcl authored
100 rescue FormulaUnspecifiedError
a785a5e @mxcl dump_config for certain exceptions
mxcl authored
101 abort "This command requires a formula argument"
1b066d7 @mxcl Better errors if missing keg or formula arguments
mxcl authored
102 rescue KegUnspecifiedError
a785a5e @mxcl dump_config for certain exceptions
mxcl authored
103 abort "This command requires a keg argument"
ea7c891 @mxcl Raise if ARGV.named and no named arguments
mxcl authored
104 rescue UsageError
105 onoe "Invalid usage"
a785a5e @mxcl dump_config for certain exceptions
mxcl authored
106 abort ARGV.usage
6b6d369 @mxcl Refactor
mxcl authored
107 rescue SystemExit
f0eb547 @mxcl Fixed SIGINT handling, so we can have our newline
mxcl authored
108 puts "Kernel.exit" if ARGV.verbose?
1912cbb @mxcl Re-raise SystemExit so the correct exit code is set
mxcl authored
109 raise
6b6d369 @mxcl Refactor
mxcl authored
110 rescue Interrupt => e
f0eb547 @mxcl Fixed SIGINT handling, so we can have our newline
mxcl authored
111 puts # seemingly a newline is typical
6b6d369 @mxcl Refactor
mxcl authored
112 exit 130
70bed07 @mxcl More tweaking of main exception handler output
mxcl authored
113 rescue BuildError => e
9b798cc @mxcl Move brew output for BuildError into BuildError
mxcl authored
114 e.dump
70bed07 @mxcl More tweaking of main exception handler output
mxcl authored
115 exit 1
116 rescue RuntimeError, SystemCallError => e
9aa121a @mxcl If exception has no message raise again
mxcl authored
117 raise if e.message.empty?
70bed07 @mxcl More tweaking of main exception handler output
mxcl authored
118 onoe e
119 puts e.backtrace if ARGV.debug?
120 exit 1
6b6d369 @mxcl Refactor
mxcl authored
121 rescue Exception => e
a785a5e @mxcl dump_config for certain exceptions
mxcl authored
122 onoe e
fcf20eb @mxcl Save config.log to ~/Library/Logs/Homebrew
mxcl authored
123 puts "#{Tty.white}Please report this bug:"
124 puts " #{Tty.em}#{ISSUES_URL}#{Tty.reset}"
70bed07 @mxcl More tweaking of main exception handler output
mxcl authored
125 puts e.backtrace
419cf71 @mxcl Return non-zero error code on errors
mxcl authored
126 exit 1
48a82e5 @mikemcquaid Exit with bad exit code on command failures.
mikemcquaid authored
127 else
128 exit 1 if Homebrew.failed?
118b41b @mxcl Refactor $foo into HOMEBREW_FOO
mxcl authored
129 end
Something went wrong with that request. Please try again.