Port Homebrew::Cmd::Prefix

This commit is contained in:
Douglas Eichelberger 2024-04-01 16:00:47 -07:00
parent b56e0b733d
commit 6a1d43337c
2 changed files with 101 additions and 92 deletions

View File

@ -1,12 +1,44 @@
# typed: true
# frozen_string_literal: true
require "cli/parser"
require "abstract_command"
require "fileutils"
module Homebrew
sig { returns(CLI::Parser) }
def self.__prefix_args
Homebrew::CLI::Parser.new do
module Cmd
class Prefix < AbstractCommand
include FileUtils
UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
UNBREWED_EXCLUDE_PATHS = %w[
*/.keepme
.github/*
bin/brew
completions/zsh/_brew
docs/*
lib/gdk-pixbuf-2.0/*
lib/gio/*
lib/node_modules/*
lib/python[23].[0-9]/*
lib/python3.[0-9][0-9]/*
lib/pypy/*
lib/pypy3/*
lib/ruby/gems/[12].*
lib/ruby/site_ruby/[12].*
lib/ruby/vendor_ruby/[12].*
manpages/brew.1
share/pypy/*
share/pypy3/*
share/info/dir
share/man/whatis
share/mime/*
texlive/*
].freeze
sig { override.returns(String) }
def self.command_name = "--prefix"
cmd_args do
description <<~EOS
Display Homebrew's install path. *Default:*
@ -24,11 +56,9 @@ module Homebrew
named_args :formula
end
end
def self.__prefix
args = __prefix_args.parse
sig { override.void }
def run
raise UsageError, "`--installed` requires a formula argument." if args.installed? && args.no_named?
if args.unbrewed?
@ -59,33 +89,9 @@ module Homebrew
end
end
UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
UNBREWED_EXCLUDE_PATHS = %w[
*/.keepme
.github/*
bin/brew
completions/zsh/_brew
docs/*
lib/gdk-pixbuf-2.0/*
lib/gio/*
lib/node_modules/*
lib/python[23].[0-9]/*
lib/python3.[0-9][0-9]/*
lib/pypy/*
lib/pypy3/*
lib/ruby/gems/[12].*
lib/ruby/site_ruby/[12].*
lib/ruby/vendor_ruby/[12].*
manpages/brew.1
share/pypy/*
share/pypy3/*
share/info/dir
share/man/whatis
share/mime/*
texlive/*
].freeze
private
def self.list_unbrewed
def list_unbrewed
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
dirs -= %w[Library Cellar Caskroom .git]
@ -104,3 +110,5 @@ module Homebrew
cd(HOMEBREW_PREFIX) { safe_system("find", *arguments) }
end
end
end
end

View File

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