Port Homebrew::Cmd::Cellar

This commit is contained in:
Douglas Eichelberger 2024-04-01 15:56:06 -07:00
parent 102051c35d
commit 754151fcb8
3 changed files with 25 additions and 23 deletions

View File

@ -6,7 +6,6 @@ require "abstract_command"
module Homebrew module Homebrew
module Cmd module Cmd
class Caskroom < AbstractCommand class Caskroom < AbstractCommand
sig { override.returns(String) } sig { override.returns(String) }
def self.command_name = "--caskroom" def self.command_name = "--caskroom"

View File

@ -1,32 +1,34 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "abstract_command"
module Homebrew module Homebrew
module_function module Cmd
class Cellar < AbstractCommand
sig { override.returns(String) }
def self.command_name = "--cellar"
def __cellar_args cmd_args do
Homebrew::CLI::Parser.new do description <<~EOS
description <<~EOS Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if
Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that directory doesn't exist, `$(brew --repository)/Cellar`.
that directory doesn't exist, `$(brew --repository)/Cellar`.
If <formula> is provided, display the location in the Cellar where <formula> 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. would be installed, without any sort of versioned directory as the last path.
EOS EOS
named_args :formula named_args :formula
end end
end
def __cellar sig { override.void }
args = __cellar_args.parse def run
if args.no_named?
if args.no_named? puts HOMEBREW_CELLAR
puts HOMEBREW_CELLAR else
else puts args.named.to_resolved_formulae.map(&:rack)
puts args.named.to_resolved_formulae.map(&:rack) end
end
end end
end end
end end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/--cellar"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew --cellar" do RSpec.describe Homebrew::Cmd::Cellar do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
it "prints Homebrew's Cellar", :integration_test do it "prints Homebrew's Cellar", :integration_test do