Port Homebrew::DevCmd::Irb
This commit is contained in:
parent
0e489a8c04
commit
afaa48bd17
@ -1,6 +1,7 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formulary"
|
||||
require "cask/cask_loader"
|
||||
require "cli/parser"
|
||||
@ -27,11 +28,9 @@ class Symbol
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def irb_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class Irb < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Enter the interactive Homebrew Ruby shell.
|
||||
EOS
|
||||
@ -41,12 +40,13 @@ module Homebrew
|
||||
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)
|
||||
sig { params(argv: T.nilable(T::Array[String])).void }
|
||||
def initialize(argv = nil) = super(argv || ARGV.dup.freeze)
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
clean_argv
|
||||
|
||||
if args.examples?
|
||||
@ -88,6 +88,8 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Remove the `--debug`, `--verbose` and `--quiet` options which cause problems
|
||||
# for IRB and have already been parsed by the CLI::Parser.
|
||||
def clean_argv
|
||||
@ -96,4 +98,6 @@ module Homebrew
|
||||
.flat_map { |options| options[0..1] }
|
||||
ARGV.reject! { |arg| global_options.include?(arg) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/irb"
|
||||
|
||||
RSpec.describe "brew irb" do
|
||||
RSpec.describe Homebrew::DevCmd::Irb do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
describe "integration test" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user