Automagically remove -cmd suffix

This commit is contained in:
Douglas Eichelberger 2024-03-21 19:51:18 -07:00
parent 97370b4e6a
commit 821f2a5ab5
4 changed files with 6 additions and 7 deletions

View File

@ -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))) }

View File

@ -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 <formula> is located.

View File

@ -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.

View File

@ -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