Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port remaining commands to use AbstractCommand #16998

Merged
merged 30 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
59adde2
Port Homebrew::Cmd::Log
dduugg Apr 1, 2024
0cb608a
Port Homebrew::Cmd::Migrate
dduugg Apr 1, 2024
a43224c
Port Homebrew::Cmd::Missing
dduugg Apr 1, 2024
c5dfac1
Port Homebrew::Cmd::NodenvSync
dduugg Apr 1, 2024
57442ab
Port Homebrew::Cmd::Options
dduugg Apr 1, 2024
7725fc6
Port Homebrew::Cmd::Outdated
dduugg Apr 1, 2024
c1b1c11
Port Homebrew::Cmd::Pin
dduugg Apr 1, 2024
31aa89a
Port Homebrew::Cmd::PostgresqlUpgradeDatabase
dduugg Apr 1, 2024
427b527
Port Homebrew::Cmd::Postinstall
dduugg Apr 1, 2024
6c260db
Port Homebrew::Cmd::PyenvSync
dduugg Apr 1, 2024
5ef0703
Port Homebrew::Cmd::RbenvSync
dduugg Apr 1, 2024
057f561
Port Homebrew::Cmd::Readall
dduugg Apr 1, 2024
d875c97
Port Homebrew::Cmd::Reinstall
dduugg Apr 1, 2024
5495ff1
Port Homebrew::Cmd::Search
dduugg Apr 1, 2024
be42d46
Port Homebrew::Cmd::TapInfo
dduugg Apr 1, 2024
841cfd9
Port Homebrew::Cmd::Tap
dduugg Apr 1, 2024
4cf9ef8
Port Homebrew::Cmd::Uninstall
dduugg Apr 1, 2024
5ccb0b0
Port Homebrew::Cmd::Unlink
dduugg Apr 1, 2024
f8caae0
Port Homebrew::Cmd::Unpin
dduugg Apr 1, 2024
48f4ada
Port Homebrew::Cmd::Untap
dduugg Apr 1, 2024
d5add65
Port Homebrew::Cmd::UpdateReport
dduugg Apr 1, 2024
1362890
Port Homebrew::Cmd::Upgrade
dduugg Apr 1, 2024
fdc95d0
Port Homebrew::Cmd::Uses
dduugg Apr 1, 2024
6d716a7
Missed one
dduugg Apr 1, 2024
7bbf0a3
Port Homebrew::Cmd::Cache
dduugg Apr 1, 2024
102051c
Port Homebrew::Cmd::Caskroom
dduugg Apr 1, 2024
754151f
Port Homebrew::Cmd::Cellar
dduugg Apr 1, 2024
b56e0b7
Port Homebrew::Cmd::Env
dduugg Apr 1, 2024
6a1d433
Port Homebrew::Cmd::Prefix
dduugg Apr 1, 2024
3f856f6
Port Homebrew::Cmd::Repository
dduugg Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 107 additions & 101 deletions Library/Homebrew/cmd/--cache.rb
Original file line number Diff line number Diff line change
@@ -1,122 +1,128 @@
# typed: strict
# frozen_string_literal: true

require "abstract_command"
require "fetch"
require "cli/parser"
require "cask/download"

module Homebrew
extend Fetch

sig { returns(CLI::Parser) }
def self.__cache_args
Homebrew::CLI::Parser.new do
description <<~EOS
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.

If <formula> is provided, display the file or directory used to cache <formula>.
EOS
flag "--os=",
description: "Show cache file for the given operating system. " \
"(Pass `all` to show cache files for all operating systems.)"
flag "--arch=",
description: "Show cache file for the given CPU architecture. " \
"(Pass `all` to show cache files for all architectures.)"
switch "-s", "--build-from-source",
description: "Show the cache file used when building from source."
switch "--force-bottle",
description: "Show the cache file used when pouring a bottle."
flag "--bottle-tag=",
description: "Show the cache file used when pouring a bottle for the given tag."
switch "--HEAD",
description: "Show the cache file used when building from HEAD."
switch "--formula", "--formulae",
description: "Only show cache files for formulae."
switch "--cask", "--casks",
description: "Only show cache files for casks."

conflicts "--build-from-source", "--force-bottle", "--bottle-tag", "--HEAD", "--cask"
conflicts "--formula", "--cask"
conflicts "--os", "--bottle-tag"
conflicts "--arch", "--bottle-tag"

named_args [:formula, :cask]
end
end

sig { void }
def self.__cache
args = __cache_args.parse

if args.no_named?
puts HOMEBREW_CACHE
return
end

formulae_or_casks = args.named.to_formulae_and_casks
os_arch_combinations = args.os_arch_combinations

formulae_or_casks.each do |formula_or_cask|
case formula_or_cask
when Formula
formula = formula_or_cask
ref = formula.loaded_from_api? ? formula.full_name : formula.path
module Cmd
class Cache < AbstractCommand
include Fetch

sig { override.returns(String) }
def self.command_name = "--cache"

cmd_args do
description <<~EOS
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.

If <formula> is provided, display the file or directory used to cache <formula>.
EOS
flag "--os=",
description: "Show cache file for the given operating system. " \
"(Pass `all` to show cache files for all operating systems.)"
flag "--arch=",
description: "Show cache file for the given CPU architecture. " \
"(Pass `all` to show cache files for all architectures.)"
switch "-s", "--build-from-source",
description: "Show the cache file used when building from source."
switch "--force-bottle",
description: "Show the cache file used when pouring a bottle."
flag "--bottle-tag=",
description: "Show the cache file used when pouring a bottle for the given tag."
switch "--HEAD",
description: "Show the cache file used when building from HEAD."
switch "--formula", "--formulae",
description: "Only show cache files for formulae."
switch "--cask", "--casks",
description: "Only show cache files for casks."

conflicts "--build-from-source", "--force-bottle", "--bottle-tag", "--HEAD", "--cask"
conflicts "--formula", "--cask"
conflicts "--os", "--bottle-tag"
conflicts "--arch", "--bottle-tag"

named_args [:formula, :cask]
end

os_arch_combinations.each do |os, arch|
SimulateSystem.with(os:, arch:) do
formula = Formulary.factory(ref)
print_formula_cache(formula, os:, arch:, args:)
end
sig { override.void }
def run
if args.no_named?
puts HOMEBREW_CACHE
return

Check warning on line 53 in Library/Homebrew/cmd/--cache.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/--cache.rb#L53

Added line #L53 was not covered by tests
end
else
cask = formula_or_cask
ref = cask.loaded_from_api? ? cask.full_name : cask.sourcefile_path

os_arch_combinations.each do |os, arch|
next if os == :linux

SimulateSystem.with(os:, arch:) do
cask = Cask::CaskLoader.load(ref)
print_cask_cache(cask)
formulae_or_casks = args.named.to_formulae_and_casks
os_arch_combinations = args.os_arch_combinations

formulae_or_casks.each do |formula_or_cask|
case formula_or_cask
when Formula
formula = formula_or_cask
ref = formula.loaded_from_api? ? formula.full_name : formula.path

os_arch_combinations.each do |os, arch|
SimulateSystem.with(os:, arch:) do
formula = Formulary.factory(ref)
print_formula_cache(formula, os:, arch:)
end
end
when Cask::Cask
cask = formula_or_cask
ref = cask.loaded_from_api? ? cask.full_name : cask.sourcefile_path

os_arch_combinations.each do |os, arch|
next if os == :linux

SimulateSystem.with(os:, arch:) do
loaded_cask = Cask::CaskLoader.load(ref)
print_cask_cache(loaded_cask)
end
end
else
raise "Invalid type: #{formula_or_cask.class}"
end
end
end
end
end

sig { params(formula: Formula, os: Symbol, arch: Symbol, args: CLI::Args).void }
def self.print_formula_cache(formula, os:, arch:, args:)
if fetch_bottle?(
formula,
force_bottle: args.force_bottle?,
bottle_tag: args.bottle_tag&.to_sym,
build_from_source_formulae: args.build_from_source_formulae,
os: args.os&.to_sym,
arch: args.arch&.to_sym,
)
bottle_tag = if (bottle_tag = args.bottle_tag&.to_sym)
Utils::Bottles::Tag.from_symbol(bottle_tag)
else
Utils::Bottles::Tag.new(system: os, arch:)
end
private

sig { params(formula: Formula, os: Symbol, arch: Symbol).void }
def print_formula_cache(formula, os:, arch:)
if fetch_bottle?(
formula,
force_bottle: args.force_bottle?,
bottle_tag: args.bottle_tag&.to_sym,
build_from_source_formulae: args.build_from_source_formulae,
os: args.os&.to_sym,
arch: args.arch&.to_sym,
)
bottle_tag = if (bottle_tag = args.bottle_tag&.to_sym)
Utils::Bottles::Tag.from_symbol(bottle_tag)
else
Utils::Bottles::Tag.new(system: os, arch:)
end

bottle = formula.bottle_for_tag(bottle_tag)

Check warning on line 107 in Library/Homebrew/cmd/--cache.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/--cache.rb#L107

Added line #L107 was not covered by tests

bottle = formula.bottle_for_tag(bottle_tag)
if bottle.nil?
opoo "Bottle for tag #{bottle_tag.to_sym.inspect} is unavailable."
return

Check warning on line 111 in Library/Homebrew/cmd/--cache.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/--cache.rb#L111

Added line #L111 was not covered by tests
end

if bottle.nil?
opoo "Bottle for tag #{bottle_tag.to_sym.inspect} is unavailable."
return
puts bottle.cached_download

Check warning on line 114 in Library/Homebrew/cmd/--cache.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/--cache.rb#L114

Added line #L114 was not covered by tests
elsif args.HEAD?
puts T.must(formula.head).cached_download
else
puts formula.cached_download
end
end

puts bottle.cached_download
elsif args.HEAD?
puts T.must(formula.head).cached_download
else
puts formula.cached_download
sig { params(cask: Cask::Cask).void }
def print_cask_cache(cask)
puts Cask::Download.new(cask).downloader.cached_location
end
end
end

sig { params(cask: Cask::Cask).void }
def self.print_cask_cache(cask)
puts Cask::Download.new(cask).downloader.cached_location
end
end
44 changes: 23 additions & 21 deletions Library/Homebrew/cmd/--caskroom.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# typed: strict
# frozen_string_literal: true

require "abstract_command"

module Homebrew
module_function
module Cmd
class Caskroom < AbstractCommand
sig { override.returns(String) }
def self.command_name = "--caskroom"

sig { returns(CLI::Parser) }
def __caskroom_args
Homebrew::CLI::Parser.new do
description <<~EOS
Display Homebrew's Caskroom path.
cmd_args do
description <<~EOS
Display Homebrew's Caskroom path.

If <cask> is provided, display the location in the Caskroom where <cask>
would be installed, without any sort of versioned directory as the last path.
EOS
If <cask> is provided, display the location in the Caskroom where <cask>
would be installed, without any sort of versioned directory as the last path.
EOS

named_args :cask
end
end

sig { void }
def __caskroom
args = __caskroom_args.parse
named_args :cask
end

if args.named.to_casks.blank?
puts Cask::Caskroom.path
else
args.named.to_casks.each do |cask|
puts "#{Cask::Caskroom.path}/#{cask.token}"
sig { override.void }
def run
if args.named.to_casks.blank?
puts Cask::Caskroom.path
else
args.named.to_casks.each do |cask|
puts "#{Cask::Caskroom.path}/#{cask.token}"
end
end
end
end
end
Expand Down
44 changes: 23 additions & 21 deletions Library/Homebrew/cmd/--cellar.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "cli/parser"
require "abstract_command"

module Homebrew
module_function
module Cmd
class Cellar < AbstractCommand
sig { override.returns(String) }
def self.command_name = "--cellar"

def __cellar_args
Homebrew::CLI::Parser.new do
description <<~EOS
Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if
that directory doesn't exist, `$(brew --repository)/Cellar`.
cmd_args do
description <<~EOS
Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if
that directory doesn't exist, `$(brew --repository)/Cellar`.

If <formula> is provided, display the location in the Cellar where <formula>
would be installed, without any sort of versioned directory as the last path.
EOS
If <formula> is provided, display the location in the Cellar where <formula>
would be installed, without any sort of versioned directory as the last path.
EOS

named_args :formula
end
end

def __cellar
args = __cellar_args.parse
named_args :formula
end

if args.no_named?
puts HOMEBREW_CELLAR
else
puts args.named.to_resolved_formulae.map(&:rack)
sig { override.void }
def run
if args.no_named?
puts HOMEBREW_CELLAR
else
puts args.named.to_resolved_formulae.map(&:rack)
end
end
end
end
end
Loading