Port Homebrew::DevCmd::Formula
This commit is contained in:
parent
2f461b1b95
commit
16b93c48e0
@ -1,32 +1,34 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "formula"
|
require "formula"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module DevCmd
|
||||||
|
class FormulaCmd < AbstractCommand
|
||||||
|
sig { returns(String) }
|
||||||
|
def self.command_name = "formula"
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def formula_args
|
description <<~EOS
|
||||||
Homebrew::CLI::Parser.new do
|
Display the path where <formula> is located.
|
||||||
description <<~EOS
|
EOS
|
||||||
Display the path where <formula> 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
|
||||||
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
|
end
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
require "dev-cmd/formula"
|
||||||
|
|
||||||
RSpec.describe "brew formula" do
|
RSpec.describe Homebrew::DevCmd::FormulaCmd do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||||
|
|
||||||
it "prints a given Formula's path", :integration_test do
|
it "prints a given Formula's path", :integration_test do
|
||||||
formula_file = setup_test_formula "testball"
|
formula_file = setup_test_formula "testball"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user