-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
irb.rb
88 lines (73 loc) 路 2.02 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# typed: false
# frozen_string_literal: true
require "formulary"
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
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def irb_args
Homebrew::CLI::Parser.new do
description <<~EOS
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)
clean_argv
if args.examples?
puts <<~EOS
'v8'.f # => instance of the v8 formula
:hub.f.latest_version_installed?
:lua.f.methods - 1.methods
:mpd.f.recursive_dependencies.reject(&:installed?)
EOS
return
end
if args.pry?
Homebrew.install_gem_setup_path! "pry"
require "pry"
else
require "irb"
end
require "formula"
require "keg"
require "cask"
ohai "Interactive Homebrew Shell", "Example commands available with: `brew irb --examples`"
if args.pry?
Pry.config.should_load_rc = false # skip loading .pryrc
Pry.config.history_file = (HOMEBREW_REPOSITORY/".pry_history").to_s
Pry.config.memory_size = 100 # max lines to save to history file
Pry.config.prompt_name = "brew"
Pry.start
else
ENV["IRBRC"] = (HOMEBREW_REPOSITORY/".irb_config").to_s
IRB.start
end
end
# Remove the `--debug`, `--verbose` and `--quiet` options which cause problems
# for IRB and have already been parsed by the CLI::Parser.
def clean_argv
global_options = Homebrew::CLI::Parser
.global_options
.flat_map { |options| options[0..1] }
ARGV.reject! { |arg| global_options.include?(arg) }
end
end