Port Homebrew::DevCmd::Formula

This commit is contained in:
Douglas Eichelberger 2024-03-21 08:31:45 -07:00
parent 2f461b1b95
commit 16b93c48e0
2 changed files with 26 additions and 23 deletions

View File

@ -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
cmd_args do
description <<~EOS
Display the path where <formula> is located.
EOS
named_args :formula, min: 1, without_api: true
end
end
def formula
args = formula_args.parse
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(&method(:puts))
formula_paths.each { puts _1 }
end
end
end
end

View File

@ -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"