Port Homebrew::DevCmd::Irb

This commit is contained in:
Douglas Eichelberger 2024-03-21 10:39:08 -07:00
parent 0e489a8c04
commit afaa48bd17
3 changed files with 73 additions and 67 deletions

View File

@ -1,6 +1,7 @@
# typed: strict
# frozen_string_literal: true
require "abstract_command"
require "cli/parser"
module Homebrew

View File

@ -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

View File

@ -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