Mike McQuaid 20a1199375
Refactor CLI to remove unless args_parsed
Refactor the CLI::Args module so it doesn't have different paths to
check arguments depending on whether the arguments have been parsed or
not. Instead, set the values we need from the global ARGV at
first, global initialisation time where they will be thrown away when
the actual arguments are parsed.

To do this some other general refactoring was needed:
- more methods made private when possible
- e.g. `HEAD?` used consistently instead of `head` before arguments
  are parsed.
- formula options are only parsed after named arguments are extracted
2020-05-05 17:47:51 +01:00

68 lines
1.3 KiB
Ruby

# 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
# work around IRB modifying ARGV.
Homebrew::CLI::Parser.new(ARGV.dup) 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
irb_args.parse
if args.examples?
puts "'v8'.f # => instance of the v8 formula"
puts ":hub.f.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/all"
ohai "Interactive Homebrew Shell"
puts "Example commands available with: brew irb --examples"
if args.pry?
Pry.start
else
IRB.start
end
end
end