Port Homebrew::DevCmd::Extract
This commit is contained in:
parent
2cc70549d8
commit
2f461b1b95
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/git"
|
||||
require "formulary"
|
||||
@ -8,11 +9,11 @@ require "software_spec"
|
||||
require "tap"
|
||||
|
||||
module Homebrew
|
||||
module DevCmd
|
||||
class Extract < AbstractCommand
|
||||
BOTTLE_BLOCK_REGEX = / bottle (?:do.+?end|:[a-z]+)\n\n/m
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.extract_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
usage_banner "`extract` [`--version=`] [`--force`] <formula> <tap>"
|
||||
description <<~EOS
|
||||
Look through repository history to find the most recent version of <formula> and
|
||||
@ -29,11 +30,9 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :tap], number: 2, without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def self.extract
|
||||
args = extract_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
if (tap_with_name = args.named.first&.then { Tap.with_formula_name(_1) })
|
||||
source_tap, name = tap_with_name
|
||||
else
|
||||
@ -149,9 +148,10 @@ module Homebrew
|
||||
path.write result
|
||||
end
|
||||
|
||||
# @private
|
||||
private
|
||||
|
||||
sig { params(repo: Pathname, name: String, file: Pathname, rev: String).returns(T.nilable(Formula)) }
|
||||
def self.formula_at_revision(repo, name, file, rev)
|
||||
def formula_at_revision(repo, name, file, rev)
|
||||
return if rev.empty?
|
||||
|
||||
contents = Utils::Git.last_revision_of_file(repo, file, before_commit: rev)
|
||||
@ -161,7 +161,7 @@ module Homebrew
|
||||
with_monkey_patch { Formulary.from_contents(name, file, contents, ignore_errors: true) }
|
||||
end
|
||||
|
||||
private_class_method def self.with_monkey_patch
|
||||
def with_monkey_patch
|
||||
# Since `method_defined?` is not a supported type guard, the use of `alias_method` below is not typesafe:
|
||||
BottleSpecification.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
@ -185,7 +185,10 @@ module Homebrew
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec, :parse_symbol_spec if method_defined?(:parse_symbol_spec)
|
||||
if method_defined?(:parse_symbol_spec)
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec,
|
||||
:parse_symbol_spec
|
||||
end
|
||||
define_method(:parse_symbol_spec) do |*|
|
||||
# do nothing
|
||||
end
|
||||
@ -222,3 +225,5 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/extract"
|
||||
|
||||
RSpec.describe "brew extract" do
|
||||
it_behaves_like "parseable arguments"
|
||||
RSpec.describe Homebrew::DevCmd::Extract do
|
||||
it_behaves_like "parseable arguments", argv: ["foo", "bar"]
|
||||
|
||||
context "when extracting a formula" do
|
||||
let!(:target) do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user