dev-cmd/extract: trim version to only digits/decimals for class & file names

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Eric Knibbe 2024-06-19 18:24:45 -04:00
parent 3cfe8e7a80
commit b8dc576647
No known key found for this signature in database
GPG Key ID: 179D9CDDDB814168

View File

@ -122,15 +122,20 @@ module Homebrew
# e.g. Foo version 1.2.3 becomes FooAT123 and resides in Foo@1.2.3.rb.
class_name = Formulary.class_s(name)
# Remove any existing version suffixes, as a new one will be added later
# The version can only contain digits with decimals in between.
version_string = version.to_s
.sub(/\D*(.+?)\D*$/, "\\1")
.gsub(/\D+/, ".")
# Remove any existing version suffixes, as a new one will be added later.
name.sub!(/\b@(.*)\z\b/i, "")
versioned_name = Formulary.class_s("#{name}@#{version}")
versioned_name = Formulary.class_s("#{name}@#{version_string}")
result.sub!("class #{class_name} < Formula", "class #{versioned_name} < Formula")
# Remove bottle blocks, they won't work.
# Remove bottle blocks, as they won't work.
result.sub!(BOTTLE_BLOCK_REGEX, "")
path = destination_tap.path/"Formula/#{name}@#{version.to_s.downcase}.rb"
path = destination_tap.path/"Formula/#{name}@#{version_string}.rb"
if path.exist?
unless args.force?
odie <<~EOS