Port Homebrew::Cmd::Readall
This commit is contained in:
parent
5ef070380c
commit
057f561d2c
@ -1,69 +1,67 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "readall"
|
require "readall"
|
||||||
require "cli/parser"
|
|
||||||
require "env_config"
|
require "env_config"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class ReadallCmd < AbstractCommand
|
||||||
|
cmd_args do
|
||||||
|
description <<~EOS
|
||||||
|
Import all items from the specified <tap>, or from all installed taps if none is provided.
|
||||||
|
This can be useful for debugging issues across all items when making
|
||||||
|
significant changes to `formula.rb`, testing the performance of loading
|
||||||
|
all items or checking if any current formulae/casks have Ruby issues.
|
||||||
|
EOS
|
||||||
|
flag "--os=",
|
||||||
|
description: "Read using the given operating system. (Pass `all` to simulate all operating systems.)"
|
||||||
|
flag "--arch=",
|
||||||
|
description: "Read using the given CPU architecture. (Pass `all` to simulate all architectures.)"
|
||||||
|
switch "--aliases",
|
||||||
|
description: "Verify any alias symlinks in each tap."
|
||||||
|
switch "--syntax",
|
||||||
|
description: "Syntax-check all of Homebrew's Ruby files (if no <tap> is passed)."
|
||||||
|
switch "--eval-all",
|
||||||
|
description: "Evaluate all available formulae and casks, whether installed or not. " \
|
||||||
|
"Implied if `HOMEBREW_EVAL_ALL` is set."
|
||||||
|
switch "--no-simulate",
|
||||||
|
description: "Don't simulate other system configurations when checking formulae and casks."
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
named_args :tap
|
||||||
def readall_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
|
||||||
Import all items from the specified <tap>, or from all installed taps if none is provided.
|
|
||||||
This can be useful for debugging issues across all items when making
|
|
||||||
significant changes to `formula.rb`, testing the performance of loading
|
|
||||||
all items or checking if any current formulae/casks have Ruby issues.
|
|
||||||
EOS
|
|
||||||
flag "--os=",
|
|
||||||
description: "Read using the given operating system. (Pass `all` to simulate all operating systems.)"
|
|
||||||
flag "--arch=",
|
|
||||||
description: "Read using the given CPU architecture. (Pass `all` to simulate all architectures.)"
|
|
||||||
switch "--aliases",
|
|
||||||
description: "Verify any alias symlinks in each tap."
|
|
||||||
switch "--syntax",
|
|
||||||
description: "Syntax-check all of Homebrew's Ruby files (if no <tap> is passed)."
|
|
||||||
switch "--eval-all",
|
|
||||||
description: "Evaluate all available formulae and casks, whether installed or not. " \
|
|
||||||
"Implied if `HOMEBREW_EVAL_ALL` is set."
|
|
||||||
switch "--no-simulate",
|
|
||||||
description: "Don't simulate other system configurations when checking formulae and casks."
|
|
||||||
|
|
||||||
named_args :tap
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def readall
|
|
||||||
args = readall_args.parse
|
|
||||||
|
|
||||||
Homebrew.with_no_api_env do
|
|
||||||
if args.syntax? && args.no_named?
|
|
||||||
scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb"
|
|
||||||
ruby_files = Dir.glob(scan_files).grep_v(%r{/(vendor)/})
|
|
||||||
|
|
||||||
Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
options = {
|
sig { override.void }
|
||||||
aliases: args.aliases?,
|
def run
|
||||||
no_simulate: args.no_simulate?,
|
Homebrew.with_no_api_env do
|
||||||
}
|
if args.syntax? && args.no_named?
|
||||||
options[:os_arch_combinations] = args.os_arch_combinations if args.os || args.arch
|
scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb"
|
||||||
|
ruby_files = Dir.glob(scan_files).grep_v(%r{/(vendor)/})
|
||||||
|
|
||||||
taps = if args.no_named?
|
Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files)
|
||||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
end
|
||||||
raise UsageError, "`brew readall` needs a tap or `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
|
||||||
|
options = {
|
||||||
|
aliases: args.aliases?,
|
||||||
|
no_simulate: args.no_simulate?,
|
||||||
|
}
|
||||||
|
options[:os_arch_combinations] = args.os_arch_combinations if args.os || args.arch
|
||||||
|
|
||||||
|
taps = if args.no_named?
|
||||||
|
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
||||||
|
raise UsageError, "`brew readall` needs a tap or `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
||||||
|
end
|
||||||
|
|
||||||
|
Tap.installed
|
||||||
|
else
|
||||||
|
args.named.to_installed_taps
|
||||||
|
end
|
||||||
|
|
||||||
|
taps.each do |tap|
|
||||||
|
Homebrew.failed = true unless Readall.valid_tap?(tap, **options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Tap.installed
|
|
||||||
else
|
|
||||||
args.named.to_installed_taps
|
|
||||||
end
|
|
||||||
|
|
||||||
taps.each do |tap|
|
|
||||||
Homebrew.failed = true unless Readall.valid_tap?(tap, **options)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
module Readall
|
module Readall
|
||||||
class << self
|
class << self
|
||||||
|
undef valid_casks?
|
||||||
|
|
||||||
def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type)
|
def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type)
|
||||||
return true if os_name == :linux
|
return true if os_name == :linux
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/readall"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew readall" do
|
RSpec.describe Homebrew::Cmd::ReadallCmd do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "imports all Formulae for a given Tap", :integration_test do
|
it "imports all Formulae for a given Tap", :integration_test do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user