-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
irb.rb
67 lines (56 loc) 路 1.33 KB
/
irb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
require "cli/parser"
class Symbol
def f(*args)
Formulary.factory(to_s, *args)
end
end
class String
def f(*args)
Formulary.factory(self, *args)
end
end
module Homebrew
module_function
def irb_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`irb` [<options>]
Enter the interactive Homebrew Ruby shell.
EOS
switch "--examples",
description: "Show several examples."
switch "--pry",
env: :pry,
description: "Use Pry instead of IRB. Implied if `HOMEBREW_PRY` is set."
end
end
def irb
# work around IRB modifying ARGV.
args = irb_args.parse(ARGV.dup.freeze)
if args.examples?
puts "'v8'.f # => instance of the v8 formula"
puts ":hub.f.latest_version_installed?"
puts ":lua.f.methods - 1.methods"
puts ":mpd.f.recursive_dependencies.reject(&:installed?)"
return
end
if args.pry?
Homebrew.install_gem_setup_path! "pry"
require "pry"
Pry.config.prompt_name = "brew"
else
require "irb"
end
require "formula"
require "keg"
require "cask"
ohai "Interactive Homebrew Shell"
puts "Example commands available with: brew irb --examples"
if args.pry?
Pry.start
else
IRB.start
end
end
end