From 821f2a5ab5444e37357fba81331f69d54a24016b Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 21 Mar 2024 19:51:18 -0700 Subject: [PATCH] Automagically remove -cmd suffix --- Library/Homebrew/abstract_command.rb | 2 +- Library/Homebrew/dev-cmd/formula.rb | 3 --- Library/Homebrew/dev-cmd/livecheck.rb | 3 --- Library/Homebrew/test/abstract_command_spec.rb | 5 +++++ 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/abstract_command.rb b/Library/Homebrew/abstract_command.rb index e7a5713755..95b086f022 100644 --- a/Library/Homebrew/abstract_command.rb +++ b/Library/Homebrew/abstract_command.rb @@ -17,7 +17,7 @@ module Homebrew class << self sig { returns(String) } - def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-") + def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-").delete_suffix("-cmd") # @return the AbstractCommand subclass associated with the brew CLI command name. sig { params(name: String).returns(T.nilable(T.class_of(AbstractCommand))) } diff --git a/Library/Homebrew/dev-cmd/formula.rb b/Library/Homebrew/dev-cmd/formula.rb index 0325436a1c..e0189b4b81 100644 --- a/Library/Homebrew/dev-cmd/formula.rb +++ b/Library/Homebrew/dev-cmd/formula.rb @@ -8,9 +8,6 @@ require "cli/parser" module Homebrew module DevCmd class FormulaCmd < AbstractCommand - sig { returns(String) } - def self.command_name = "formula" - cmd_args do description <<~EOS Display the path where is located. diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 8537ed3d6f..c02deece81 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -10,9 +10,6 @@ require "livecheck/strategy" module Homebrew module DevCmd class LivecheckCmd < AbstractCommand - sig { returns(String) } - def self.command_name = "livecheck" - cmd_args do description <<~EOS Check for newer versions of formulae and/or casks from upstream. diff --git a/Library/Homebrew/test/abstract_command_spec.rb b/Library/Homebrew/test/abstract_command_spec.rb index a30080bd89..e3ae8add92 100644 --- a/Library/Homebrew/test/abstract_command_spec.rb +++ b/Library/Homebrew/test/abstract_command_spec.rb @@ -39,6 +39,11 @@ RSpec.describe Homebrew::AbstractCommand do expect(described_class.command("test-cat")).to be(TestCat) end + it "removes -cmd suffix from command name" do + require "dev-cmd/formula" + expect(Homebrew::DevCmd::FormulaCmd.command_name).to eq("formula") + end + describe "when command name is overridden" do before do tac = Class.new(described_class) do