From 3ea76b84980ecd67d89753743403dd220d4b84d8 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 1 Dec 2024 10:44:53 -0800 Subject: [PATCH] Avoid re-defining #formula? --- Library/Homebrew/cli/args.rb | 10 ++++++++-- Library/Homebrew/cli/parser.rb | 8 +------- Library/Homebrew/extend/os/linux/cli/parser.rb | 8 +------- Library/Homebrew/extend/os/parser.rb | 9 +++++++++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index bd80f8325a..7668207e79 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -55,9 +55,15 @@ module Homebrew sig { returns(T::Boolean) } def build_from_source? = false + sig { returns(T::Boolean) } + def cask? = false + sig { returns(T::Boolean) } def force_bottle? = false + # Defined in extend/os: + # def formula; end + sig { returns(T::Boolean) } def HEAD? = false @@ -122,9 +128,9 @@ module Homebrew sig { returns(T.nilable(Symbol)) } def only_formula_or_cask - if invoke_if_respond_to(:formula?) && !invoke_if_respond_to(:cask?) + if formula? && !cask? :formula - elsif invoke_if_respond_to(:cask?) && !invoke_if_respond_to(:formula?) + elsif cask? && !formula? :cask end end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 9c5eba6ee6..fc3860c468 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -393,10 +393,7 @@ module Homebrew end unless ignore_invalid_options - unless @is_dev_cmd - set_default_options - validate_options - end + validate_options unless @is_dev_cmd check_constraint_violations check_named_args(named_args) end @@ -416,9 +413,6 @@ module Homebrew @args end - sig { void } - def set_default_options; end - sig { void } def validate_options; end diff --git a/Library/Homebrew/extend/os/linux/cli/parser.rb b/Library/Homebrew/extend/os/linux/cli/parser.rb index c4f2d7554e..ab9b0af050 100644 --- a/Library/Homebrew/extend/os/linux/cli/parser.rb +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -9,15 +9,9 @@ module OS requires_ancestor { Homebrew::CLI::Parser } - sig { void } - def set_default_options - args.define_singleton_method(:formula?) { true } if args.respond_to?(:formula?) - end - sig { void } def validate_options - return unless args.respond_to?(:cask?) - return unless T.unsafe(args).cask? + return unless args.cask? # NOTE: We don't raise an error here because we don't want # to print the help page or a stack trace. diff --git a/Library/Homebrew/extend/os/parser.rb b/Library/Homebrew/extend/os/parser.rb index fcf7990252..9c5095b4e2 100644 --- a/Library/Homebrew/extend/os/parser.rb +++ b/Library/Homebrew/extend/os/parser.rb @@ -2,3 +2,12 @@ # frozen_string_literal: true require "extend/os/linux/cli/parser" if OS.linux? + +module Homebrew + module CLI + class Args + sig { returns(T::Boolean) } + def formula? = OS.linux? + end + end +end