irb: Use Parser to parse args
This commit is contained in:
parent
2ec684a123
commit
164f47a108
@ -5,6 +5,9 @@
|
|||||||
#: If `--pry` is passed or HOMEBREW_PRY is set, pry will be
|
#: If `--pry` is passed or HOMEBREW_PRY is set, pry will be
|
||||||
#: used instead of irb.
|
#: used instead of irb.
|
||||||
|
|
||||||
|
require "cli_parser"
|
||||||
|
require "utils/env"
|
||||||
|
|
||||||
class Symbol
|
class Symbol
|
||||||
def f(*args)
|
def f(*args)
|
||||||
Formulary.factory(to_s, *args)
|
Formulary.factory(to_s, *args)
|
||||||
@ -21,7 +24,12 @@ module Homebrew
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def irb
|
def irb
|
||||||
if ARGV.include? "--examples"
|
args = Homebrew::CLI::Parser.new do
|
||||||
|
switch "--examples"
|
||||||
|
switch "--pry"
|
||||||
|
end.parse
|
||||||
|
|
||||||
|
if args.examples?
|
||||||
puts "'v8'.f # => instance of the v8 formula"
|
puts "'v8'.f # => instance of the v8 formula"
|
||||||
puts ":hub.f.installed?"
|
puts ":hub.f.installed?"
|
||||||
puts ":lua.f.methods - 1.methods"
|
puts ":lua.f.methods - 1.methods"
|
||||||
@ -29,7 +37,7 @@ module Homebrew
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.pry?
|
if args.pry? || Utils::EnvVars.pry?
|
||||||
Homebrew.install_gem_setup_path! "pry"
|
Homebrew.install_gem_setup_path! "pry"
|
||||||
require "pry"
|
require "pry"
|
||||||
Pry.config.prompt_name = "brew"
|
Pry.config.prompt_name = "brew"
|
||||||
@ -45,7 +53,7 @@ module Homebrew
|
|||||||
|
|
||||||
ohai "Interactive Homebrew Shell"
|
ohai "Interactive Homebrew Shell"
|
||||||
puts "Example commands available with: brew irb --examples"
|
puts "Example commands available with: brew irb --examples"
|
||||||
if ARGV.pry?
|
if args.pry? || Utils::EnvVars.pry?
|
||||||
Pry.start
|
Pry.start
|
||||||
else
|
else
|
||||||
IRB.start
|
IRB.start
|
||||||
|
|||||||
@ -268,10 +268,6 @@ module HomebrewArgvExtension
|
|||||||
include? "--fetch-HEAD"
|
include? "--fetch-HEAD"
|
||||||
end
|
end
|
||||||
|
|
||||||
def pry?
|
|
||||||
include?("--pry") || !ENV["HOMEBREW_PRY"].nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
||||||
def switch?(char)
|
def switch?(char)
|
||||||
return false if char.length > 1
|
return false if char.length > 1
|
||||||
|
|||||||
9
Library/Homebrew/utils/env.rb
Normal file
9
Library/Homebrew/utils/env.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module Utils
|
||||||
|
module EnvVars
|
||||||
|
class << self
|
||||||
|
def pry?
|
||||||
|
!ENV["HOMEBREW_PRY"].nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user