bump-revision: use Utils::AST
This commit is contained in:
parent
aaf7bc2bc5
commit
4520c05957
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
require "utils/ast"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
@ -36,56 +37,25 @@ module Homebrew
|
|||||||
|
|
||||||
args.named.to_formulae.each do |formula|
|
args.named.to_formulae.each do |formula|
|
||||||
current_revision = formula.revision
|
current_revision = formula.revision
|
||||||
|
text = "revision #{current_revision+1}"
|
||||||
if current_revision.zero?
|
|
||||||
formula_spec = formula.stable
|
|
||||||
hash_type, old_hash = if (checksum = formula_spec.checksum)
|
|
||||||
[checksum.hash_type, checksum.hexdigest]
|
|
||||||
end
|
|
||||||
|
|
||||||
old = if formula.license
|
|
||||||
license_string = case formula.license
|
|
||||||
when String
|
|
||||||
"\"#{formula.license}\""
|
|
||||||
when Symbol
|
|
||||||
":#{formula.license}"
|
|
||||||
else
|
|
||||||
formula.license.to_s.gsub(/:(\w+)=>/, '\1: ') # Change `:any_of=>` to `any_of: `
|
|
||||||
.tr("{}", "") # Remove braces
|
|
||||||
.gsub(/=>with: "([a-zA-Z0-9-]+)"/, ' => { with: "\1" }') # Add braces and spacing around exceptions
|
|
||||||
end
|
|
||||||
# insert replacement revision after license
|
|
||||||
<<~EOS
|
|
||||||
license #{license_string}
|
|
||||||
EOS
|
|
||||||
elsif formula.path.read.include?("stable do\n")
|
|
||||||
# insert replacement revision after homepage
|
|
||||||
<<~EOS
|
|
||||||
homepage "#{formula.homepage}"
|
|
||||||
EOS
|
|
||||||
elsif hash_type
|
|
||||||
# insert replacement revision after hash
|
|
||||||
<<~EOS
|
|
||||||
#{hash_type} "#{old_hash}"
|
|
||||||
EOS
|
|
||||||
else
|
|
||||||
# insert replacement revision after :revision
|
|
||||||
<<~EOS
|
|
||||||
revision: "#{formula_spec.specs[:revision]}"
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
replacement = "#{old} revision 1\n"
|
|
||||||
|
|
||||||
else
|
|
||||||
old = "revision #{current_revision}"
|
|
||||||
replacement = "revision #{current_revision+1}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if args.dry_run?
|
if args.dry_run?
|
||||||
ohai "replace #{old.inspect} with #{replacement.inspect}" unless args.quiet?
|
unless args.quiet?
|
||||||
|
if current_revision.zero?
|
||||||
|
ohai "add #{text.inspect}"
|
||||||
|
else
|
||||||
|
old = "revision #{current_revision}"
|
||||||
|
ohai "replace #{old.inspect} with #{text.inspect}"
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Utils::Inreplace.inreplace(formula.path) do |s|
|
Utils::Inreplace.inreplace(formula.path) do |s|
|
||||||
s.gsub!(old, replacement)
|
s = s.inreplace_string
|
||||||
|
if current_revision.zero?
|
||||||
|
Utils::AST.add_formula_stanza!(s, name: :revision, text: text)
|
||||||
|
else
|
||||||
|
Utils::AST.replace_formula_stanza!(s, name: :revision, replacement: text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user