Port Homebrew::DevCmd::Cat

This commit is contained in:
Douglas Eichelberger 2024-03-18 20:31:44 -07:00
parent df42e9cfb3
commit 55a0991902
2 changed files with 51 additions and 47 deletions

View File

@ -1,12 +1,15 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
require "cli/parser"
module Homebrew
sig { returns(CLI::Parser) }
def self.cat_args
Homebrew::CLI::Parser.new do
module DevCmd
class Cat < AbstractCommand
include FileUtils
cmd_args do
description <<~EOS
Display the source of a <formula> or <cask>.
EOS
@ -20,11 +23,9 @@ module Homebrew
named_args [:formula, :cask], min: 1, without_api: true
end
end
def self.cat
args = cat_args.parse
sig { override.void }
def run
cd HOMEBREW_REPOSITORY do
pager = if Homebrew::EnvConfig.bat?
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
@ -60,3 +61,5 @@ module Homebrew
end
end
end
end
end

View File

@ -1,9 +1,10 @@
# frozen_string_literal: true
require "cmd/shared_examples/args_parse"
require "dev-cmd/cat"
RSpec.describe "brew cat" do
it_behaves_like "parseable arguments"
RSpec.describe Homebrew::DevCmd::Cat do
it_behaves_like "parseable arguments", argv: ["foo"]
it "prints the content of a given Formula", :integration_test do
formula_file = setup_test_formula "testball"