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