Merge pull request #2278 from reitermarkus/cask-_audit_modified_casks
Refactor `brew cask _audit_modified_casks`.
This commit is contained in:
commit
0a0c305111
@ -3,40 +3,38 @@ module Hbc
|
|||||||
class InternalAuditModifiedCasks < InternalUseBase
|
class InternalAuditModifiedCasks < InternalUseBase
|
||||||
RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze
|
RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze
|
||||||
|
|
||||||
class << self
|
def self.needs_init?
|
||||||
def needs_init?
|
true
|
||||||
true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def run(*args)
|
def self.run(*args)
|
||||||
commit_range = commit_range(args)
|
commit_range = commit_range(args)
|
||||||
cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i }
|
cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i }
|
||||||
new(commit_range, cleanup: cleanup).run
|
new(commit_range, cleanup: cleanup).run
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit_range(args)
|
def self.commit_range(args)
|
||||||
posargs = args.reject { |a| a.empty? || a.chars.first == "-" }
|
posargs = args.reject { |a| a.empty? || a.chars.first == "-" }
|
||||||
odie usage unless posargs.size == 1
|
odie usage unless posargs.size == 1
|
||||||
posargs.first
|
posargs.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def posargs(args)
|
def self.posargs(args)
|
||||||
args.reject { |a| a.empty? || a.chars.first == "-" }
|
args.reject { |a| a.empty? || a.chars.first == "-" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def usage
|
def self.usage
|
||||||
<<-EOS.undent
|
<<-EOS.undent
|
||||||
Usage: brew cask _audit_modified_casks [options...] <commit range>
|
Usage: brew cask _audit_modified_casks [options...] <commit range>
|
||||||
|
|
||||||
Given a range of Git commits, find any Casks that were modified and run `brew
|
Given a range of Git commits, find any Casks that were modified and run `brew
|
||||||
cask audit' on them. If the `url', `version', or `sha256' stanzas were modified,
|
cask audit' on them. If the `url', `version', or `sha256' stanzas were modified,
|
||||||
run with the `--download' flag to verify the hash.
|
run with the `--download' flag to verify the hash.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-c, --cleanup
|
-c, --cleanup
|
||||||
Remove all cached downloads. Use with care.
|
Remove all cached downloads. Use with care.
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(commit_range, cleanup: false)
|
def initialize(commit_range, cleanup: false)
|
||||||
@ -85,7 +83,7 @@ module Hbc
|
|||||||
@modified_casks = modified_cask_files.map { |f| Hbc.load(f) }
|
@modified_casks = modified_cask_files.map { |f| Hbc.load(f) }
|
||||||
if @modified_casks.any?
|
if @modified_casks.any?
|
||||||
num_modified = @modified_casks.size
|
num_modified = @modified_casks.size
|
||||||
ohai "#{num_modified} modified #{pluralize("cask", num_modified)}: " \
|
ohai "#{num_modified} modified cask#{plural(num_modified)}: " \
|
||||||
"#{@modified_casks.join(" ")}"
|
"#{@modified_casks.join(" ")}"
|
||||||
end
|
end
|
||||||
@modified_casks
|
@modified_casks
|
||||||
@ -122,15 +120,10 @@ module Hbc
|
|||||||
def report_failures
|
def report_failures
|
||||||
return if failed_casks.empty?
|
return if failed_casks.empty?
|
||||||
num_failed = failed_casks.size
|
num_failed = failed_casks.size
|
||||||
cask_pluralized = pluralize("cask", num_failed)
|
odie "audit failed for #{num_failed} cask#{plural(num_failed)}: " \
|
||||||
odie "audit failed for #{num_failed} #{cask_pluralized}: " \
|
|
||||||
"#{failed_casks.join(" ")}"
|
"#{failed_casks.join(" ")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def pluralize(str, num)
|
|
||||||
num == 1 ? str : "#{str}s"
|
|
||||||
end
|
|
||||||
|
|
||||||
def cleanup
|
def cleanup
|
||||||
Cleanup.run if cleanup?
|
Cleanup.run if cleanup?
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user