diff --git a/Library/Homebrew/dev-cmd/formula.rb b/Library/Homebrew/dev-cmd/formula.rb index 7f08d465ba..0325436a1c 100644 --- a/Library/Homebrew/dev-cmd/formula.rb +++ b/Library/Homebrew/dev-cmd/formula.rb @@ -1,32 +1,34 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "formula" require "cli/parser" module Homebrew - module_function + module DevCmd + class FormulaCmd < AbstractCommand + sig { returns(String) } + def self.command_name = "formula" - sig { returns(CLI::Parser) } - def formula_args - Homebrew::CLI::Parser.new do - description <<~EOS - Display the path where is located. - EOS + cmd_args do + description <<~EOS + Display the path where is located. + EOS - named_args :formula, min: 1, without_api: true + named_args :formula, min: 1, without_api: true + end + + sig { override.void } + def run + formula_paths = args.named.to_paths(only: :formula).select(&:exist?) + if formula_paths.blank? && args.named + .to_paths(only: :cask) + .any?(&:exist?) + odie "Found casks but did not find formulae!" + end + formula_paths.each { puts _1 } + end end end - - def formula - args = formula_args.parse - - formula_paths = args.named.to_paths(only: :formula).select(&:exist?) - if formula_paths.blank? && args.named - .to_paths(only: :cask) - .any?(&:exist?) - odie "Found casks but did not find formulae!" - end - formula_paths.each(&method(:puts)) - end end diff --git a/Library/Homebrew/test/dev-cmd/formula_spec.rb b/Library/Homebrew/test/dev-cmd/formula_spec.rb index 73949595a3..722580631d 100644 --- a/Library/Homebrew/test/dev-cmd/formula_spec.rb +++ b/Library/Homebrew/test/dev-cmd/formula_spec.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "dev-cmd/formula" -RSpec.describe "brew formula" do - it_behaves_like "parseable arguments" +RSpec.describe Homebrew::DevCmd::FormulaCmd do + it_behaves_like "parseable arguments", argv: ["foo"] it "prints a given Formula's path", :integration_test do formula_file = setup_test_formula "testball"