aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cask')
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact.rb16
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/base.rb15
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/binary.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/moved.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/pkg.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/relocated.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/audit.rb25
-rw-r--r--Library/Homebrew/cask/lib/hbc/auditor.rb12
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask_loader.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb160
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/--version.rb11
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb45
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb (renamed from Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb)2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/audit.rb48
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/base.rb25
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cat.rb21
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cleanup.rb45
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/create.rb19
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/doctor.rb51
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/edit.rb19
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/fetch.rb17
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/home.rb21
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/info.rb34
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/install.rb38
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb23
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb43
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb20
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_help.rb12
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb55
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/list.rb43
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/options.rb64
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/outdated.rb22
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/reinstall.rb17
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/search.rb11
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb34
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/uninstall.rb19
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/zap.rb15
-rw-r--r--Library/Homebrew/cask/lib/hbc/container.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/cab.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/dmg.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/gpg.rb41
-rw-r--r--Library/Homebrew/cask/lib/hbc/download_strategy.rb22
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/appcast.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/exceptions.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb47
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils/file.rb14
52 files changed, 658 insertions, 526 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact.rb
index b155a125a..074d15017 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact.rb
@@ -25,10 +25,17 @@ require "hbc/artifact/zap"
module Hbc
module Artifact
- # NOTE: order is important here, since we want to extract nested containers
- # before we handle any other artifacts
+ # NOTE: Order is important here!
+ #
+ # The `uninstall` stanza should be run first, as it may
+ # depend on other artifacts still being installed.
+ #
+ # We want to extract nested containers before we
+ # handle any other artifacts.
+ #
TYPES = [
PreflightBlock,
+ Uninstall,
NestedContainer,
Installer,
App,
@@ -49,17 +56,16 @@ module Hbc
VstPlugin,
Vst3Plugin,
ScreenSaver,
- Uninstall,
PostflightBlock,
Zap,
].freeze
- def self.for_cask(cask, command: SystemCommand, force: false)
+ def self.for_cask(cask, options = {})
odebug "Determining which artifacts are present in Cask #{cask}"
TYPES
.select { |klass| klass.me?(cask) }
- .map { |klass| klass.new(cask, command: command, force: force) }
+ .map { |klass| klass.new(cask, options) }
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/base.rb b/Library/Homebrew/cask/lib/hbc/artifact/base.rb
index 924493fc0..2d9330b13 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/base.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/base.rb
@@ -10,7 +10,7 @@ module Hbc
end
def self.artifact_english_article
- @artifact_english_article ||= artifact_english_name =~ /^[aeiou]/i ? "an" : "a"
+ @artifact_english_article ||= (artifact_english_name =~ /^[aeiou]/i) ? "an" : "a"
end
def self.artifact_dsl_key
@@ -43,7 +43,7 @@ module Hbc
unless unknown_keys.empty?
opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.}
end
- arguments.reject! { |k| !permitted_keys.include?(k) }
+ arguments.select! { |k| permitted_keys.include?(k) }
# key warnings
override_keys = override_arguments.keys
@@ -65,10 +65,19 @@ module Hbc
{}
end
- def initialize(cask, command: SystemCommand, force: false)
+ def verbose?
+ @verbose
+ end
+
+ def force?
+ @force
+ end
+
+ def initialize(cask, command: SystemCommand, force: false, verbose: false)
@cask = cask
@command = command
@force = force
+ @verbose = verbose
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
index 21d123ab9..7178c2af6 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb
@@ -3,10 +3,6 @@ require "hbc/artifact/symlinked"
module Hbc
module Artifact
class Binary < Symlinked
- def install_phase
- super if CLI.binaries?
- end
-
def link
super
return if source.executable?
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
index eaaa49e20..3fe969c0c 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
@@ -20,7 +20,7 @@ module Hbc
def move
if Utils.path_occupied?(target)
message = "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'"
- raise CaskError, "#{message}." unless force
+ raise CaskError, "#{message}." unless force?
opoo "#{message}; overwriting."
delete
end
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
index c43481c82..be0a6be71 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
@@ -48,7 +48,7 @@ module Hbc
"-pkg", source,
"-target", "/"
]
- args << "-verboseR" if CLI.verbose?
+ args << "-verboseR" if verbose?
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
with_choices_file do |choices_path|
args << "-applyChoiceChangesXML" << choices_path if choices_path
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
index 7757d32d0..4dba46c9d 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
@@ -35,10 +35,10 @@ module Hbc
altnames = "(#{altnames})"
# Some packges are shipped as u=rx (e.g. Bitcoin Core)
- @command.run!("/bin/chmod", args: ["--", "u+rw", file.to_s, file.realpath.to_s])
+ @command.run!("/bin/chmod", args: ["--", "u+rw", file, file.realpath])
@command.run!("/usr/bin/xattr",
- args: ["-w", ALT_NAME_ATTRIBUTE, altnames, file.to_s],
+ args: ["-w", ALT_NAME_ATTRIBUTE, altnames, file],
print_stderr: false)
end
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb b/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb
index 478f313b5..7dc772380 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb
@@ -173,7 +173,7 @@ module Hbc
unless executable_path.exist?
message = "uninstall script #{executable} does not exist"
- raise CaskError, "#{message}." unless force
+ raise CaskError, "#{message}." unless force?
opoo "#{message}, skipping."
return
end
@@ -197,9 +197,7 @@ module Hbc
paths.each do |path|
resolved_path = Pathname.new(path)
- if path.start_with?("~")
- resolved_path = resolved_path.expand_path
- end
+ resolved_path = resolved_path.expand_path if path.start_with?("~")
if resolved_path.relative? || resolved_path.split.any? { |part| part.to_s == ".." }
opoo "Skipping #{Formatter.identifier(action)} for relative path '#{path}'."
diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb
index 12cefb939..cee1fe807 100644
--- a/Library/Homebrew/cask/lib/hbc/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/audit.rb
@@ -1,16 +1,18 @@
require "hbc/checkable"
require "hbc/download"
require "digest"
+require "utils/git"
module Hbc
class Audit
include Checkable
- attr_reader :cask, :download
+ attr_reader :cask, :commit_range, :download
- def initialize(cask, download: false, check_token_conflicts: false, command: SystemCommand)
+ def initialize(cask, download: false, check_token_conflicts: false, commit_range: nil, command: SystemCommand)
@cask = cask
@download = download
+ @commit_range = commit_range
@check_token_conflicts = check_token_conflicts
@command = command
end
@@ -21,6 +23,7 @@ module Hbc
def run!
check_required_stanzas
+ check_version_and_checksum
check_version
check_sha256
check_appcast
@@ -57,6 +60,24 @@ module Hbc
add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty?
end
+ def check_version_and_checksum
+ return if @cask.sourcefile_path.nil?
+
+ tap = Tap.select { |t| t.cask_file?(@cask.sourcefile_path) }.first
+ return if tap.nil?
+
+ return if commit_range.nil?
+ previous_cask_contents = Git.last_revision_of_file(tap.path, @cask.sourcefile_path, before_commit: commit_range)
+ return if previous_cask_contents.empty?
+
+ previous_cask = CaskLoader.load_from_string(previous_cask_contents)
+
+ return unless previous_cask.version == cask.version
+ return if previous_cask.sha256 == cask.sha256
+
+ add_error "only sha256 changed (see: https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/sha256.md)"
+ end
+
def check_version
return unless cask.version
check_no_string_version_latest
diff --git a/Library/Homebrew/cask/lib/hbc/auditor.rb b/Library/Homebrew/cask/lib/hbc/auditor.rb
index ec17f3cad..48f36a54d 100644
--- a/Library/Homebrew/cask/lib/hbc/auditor.rb
+++ b/Library/Homebrew/cask/lib/hbc/auditor.rb
@@ -1,14 +1,15 @@
module Hbc
class Auditor
- def self.audit(cask, audit_download: false, check_token_conflicts: false)
- new(cask, audit_download, check_token_conflicts).audit
+ def self.audit(cask, audit_download: false, check_token_conflicts: false, commit_range: nil)
+ new(cask, audit_download, check_token_conflicts, commit_range).audit
end
- attr_reader :cask
+ attr_reader :cask, :commit_range
- def initialize(cask, audit_download, check_token_conflicts)
+ def initialize(cask, audit_download, check_token_conflicts, commit_range)
@cask = cask
@audit_download = audit_download
+ @commit_range = commit_range
@check_token_conflicts = check_token_conflicts
end
@@ -50,7 +51,8 @@ module Hbc
def audit_cask_instance(cask)
download = audit_download? && Download.new(cask)
audit = Audit.new(cask, download: download,
- check_token_conflicts: check_token_conflicts?)
+ check_token_conflicts: check_token_conflicts?,
+ commit_range: commit_range)
audit.run!
puts audit.summary
audit.success?
diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb
index a193a394e..e1cdb5dea 100644
--- a/Library/Homebrew/cask/lib/hbc/cask.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask.rb
@@ -66,7 +66,7 @@ module Hbc
return [] if current == version
# collect all installed versions that are different than tap version and return them
- installed.select { |v| v != version }
+ installed.reject { |v| v == version }
end
def to_s
@@ -74,8 +74,6 @@ module Hbc
end
def dumpcask
- return unless CLI.debug?
-
odebug "Cask instance dumps in YAML:"
odebug "Cask instance toplevel:", to_yaml
[
diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
index c392e6b72..a0c44d9b4 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -54,7 +54,7 @@ module Hbc
class FromURILoader < FromPathLoader
def self.can_load?(ref)
- !(ref.to_s !~ ::URI.regexp)
+ ref.to_s.match?(::URI.regexp)
end
def initialize(url)
@@ -80,7 +80,7 @@ module Hbc
class FromTapLoader < FromPathLoader
def self.can_load?(ref)
- !(ref.to_s !~ HOMEBREW_TAP_CASK_REGEX)
+ ref.to_s.match?(HOMEBREW_TAP_CASK_REGEX)
end
def initialize(tapped_name)
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index aa795fc59..99980b88d 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -2,8 +2,9 @@ require "optparse"
require "shellwords"
require "extend/optparse"
+require "hbc/cli/options"
-require "hbc/cli/base"
+require "hbc/cli/abstract_command"
require "hbc/cli/audit"
require "hbc/cli/cat"
require "hbc/cli/cleanup"
@@ -23,7 +24,7 @@ require "hbc/cli/uninstall"
require "hbc/cli/--version"
require "hbc/cli/zap"
-require "hbc/cli/internal_use_base"
+require "hbc/cli/abstract_internal_command"
require "hbc/cli/internal_audit_modified_casks"
require "hbc/cli/internal_appcast_checkpoint"
require "hbc/cli/internal_checkurl"
@@ -44,54 +45,36 @@ module Hbc
"remove" => "uninstall",
"abv" => "info",
"dr" => "doctor",
- # aliases from Homebrew that we don't (yet) support
- # 'ln' => 'link',
- # 'configure' => 'diy',
- # '--repo' => '--repository',
- # 'environment' => '--env',
- # '-c1' => '--config',
}.freeze
- OPTIONS = {
- "--caskroom=" => :caskroom=,
- "--appdir=" => :appdir=,
- "--colorpickerdir=" => :colorpickerdir=,
- "--prefpanedir=" => :prefpanedir=,
- "--qlplugindir=" => :qlplugindir=,
- "--dictionarydir=" => :dictionarydir=,
- "--fontdir=" => :fontdir=,
- "--servicedir=" => :servicedir=,
- "--input_methoddir=" => :input_methoddir=,
- "--internet_plugindir=" => :internet_plugindir=,
- "--audio_unit_plugindir=" => :audio_unit_plugindir=,
- "--vst_plugindir=" => :vst_plugindir=,
- "--vst3_plugindir=" => :vst3_plugindir=,
- "--screen_saverdir=" => :screen_saverdir=,
- }.freeze
+ include Options
- FLAGS = {
- ["--[no-]binaries", :binaries] => true,
- ["--debug", :debug] => false,
- ["--verbose", :verbose] => false,
- ["--outdated", :outdated] => false,
- ["--help", :help] => false,
- }.freeze
+ option "--appdir=PATH", ->(value) { Hbc.appdir = value }
+ option "--colorpickerdir=PATH", ->(value) { Hbc.colorpickerdir = value }
+ option "--prefpanedir=PATH", ->(value) { Hbc.prefpanedir = value }
+ option "--qlplugindir=PATH", ->(value) { Hbc.qlplugindir = value }
+ option "--dictionarydir=PATH", ->(value) { Hbc.dictionarydir = value }
+ option "--fontdir=PATH", ->(value) { Hbc.fontdir = value }
+ option "--servicedir=PATH", ->(value) { Hbc.servicedir = value }
+ option "--input_methoddir=PATH", ->(value) { Hbc.input_methoddir = value }
+ option "--internet_plugindir=PATH", ->(value) { Hbc.internet_plugindir = value }
+ option "--audio_unit_plugindir=PATH", ->(value) { Hbc.audio_unit_plugindir = value }
+ option "--vst_plugindir=PATH", ->(value) { Hbc.vst_plugindir = value }
+ option "--vst3_plugindir=PATH", ->(value) { Hbc.vst3_plugindir = value }
+ option "--screen_saverdir=PATH", ->(value) { Hbc.screen_saverdir = value }
- FLAGS.each do |(_, method), default_value|
- instance_variable_set(:"@#{method}", default_value)
+ option "--help", :help, false
- define_singleton_method(:"#{method}=") do |arg|
- instance_variable_set(:"@#{method}", arg)
- end
+ # handled in OS::Mac
+ option "--language a,b,c", ->(*) { raise OptionParser::InvalidOption }
- define_singleton_method(:"#{method}?") do
- instance_variable_get(:"@#{method}")
- end
- end
+ # override default handling of --version
+ option "--version", ->(*) { raise OptionParser::InvalidOption }
def self.command_classes
@command_classes ||= constants.map(&method(:const_get))
- .select { |sym| sym.respond_to?(:run) }
+ .select { |klass| klass.respond_to?(:run) }
+ .reject(&:abstract?)
.sort_by(&:command_name)
end
@@ -99,21 +82,21 @@ module Hbc
@commands ||= command_classes.map(&:command_name)
end
- def self.lookup_command(command_string)
+ def self.lookup_command(command_name)
@lookup ||= Hash[commands.zip(command_classes)]
- command_string = ALIASES.fetch(command_string, command_string)
- @lookup.fetch(command_string, command_string)
+ command_name = ALIASES.fetch(command_name, command_name)
+ @lookup.fetch(command_name, command_name)
end
def self.should_init?(command)
- (command.is_a? Class) && (command < CLI::Base) && command.needs_init?
+ command.is_a?(Class) && !command.abstract? && command.needs_init?
end
def self.run_command(command, *rest)
if command.respond_to?(:run)
# usual case: built-in command verb
command.run(*rest)
- elsif require? which("brewcask-#{command}.rb").to_s
+ elsif require?(which("brewcask-#{command}.rb"))
# external command as Ruby library on PATH, Homebrew-style
elsif command.to_s.include?("/") && require?(command.to_s)
# external command as Ruby library with literal path, useful
@@ -145,20 +128,26 @@ module Hbc
end
end
- def self.process(arguments)
- unless ENV["MACOS_VERSION"].nil?
- MacOS.full_version = ENV["MACOS_VERSION"]
- end
+ def self.run(*args)
+ new(*args).run
+ end
+
+ def initialize(*args)
+ @args = process_options(*args)
+ end
+
+ def run
+ command_name, *args = *@args
+ command = help? ? "help" : self.class.lookup_command(command_name)
+
+ MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
- command_string, *rest = *arguments
- rest = process_options(rest)
- command = help? ? "help" : lookup_command(command_string)
Hbc.default_tap.install unless Hbc.default_tap.installed?
- Hbc.init if should_init?(command)
- run_command(command, *rest)
- rescue CaskError, CaskSha256MismatchError, ArgumentError => e
+ Hbc.init if self.class.should_init?(command)
+ self.class.run_command(command, *args)
+ rescue CaskError, CaskSha256MismatchError, ArgumentError, OptionParser::InvalidOption => e
msg = e.message
- msg << e.backtrace.join("\n") if debug?
+ msg << e.backtrace.join("\n") if ARGV.debug?
onoe msg
exit 1
rescue StandardError, ScriptError, NoMemoryError => e
@@ -188,60 +177,25 @@ module Hbc
list.sort
end
- def self.parser
- # If you modify these arguments, please update USAGE.md
- @parser ||= OptionParser.new do |opts|
- opts.on("--language STRING") do
- # handled in OS::Mac
- end
-
- OPTIONS.each do |option, method|
- opts.on("#{option}" "PATH", Pathname) do |path|
- Hbc.public_send(method, path)
- end
- end
+ def process_options(*args)
+ all_args = Shellwords.shellsplit(ENV["HOMEBREW_CASK_OPTS"] || "") + args
- opts.on("--binarydir=PATH") do
- opoo <<-EOS.undent
- Option --binarydir is obsolete!
- Homebrew-Cask now uses the same location as your Homebrew installation for executable links.
- EOS
- end
+ non_options = []
- FLAGS.keys.each do |flag, method|
- opts.on(flag) do |bool|
- send(:"#{method}=", bool)
- end
- end
-
- opts.on("--version") do
- raise OptionParser::InvalidOption # override default handling of --version
- end
+ if idx = all_args.index("--")
+ non_options += all_args.drop(idx)
+ all_args = all_args.first(idx)
end
- end
- def self.process_options(args)
- all_args = Shellwords.shellsplit(ENV["HOMEBREW_CASK_OPTS"] || "") + args
- remaining = []
- until all_args.empty?
+ remaining = all_args.select do |arg|
begin
- head = all_args.shift
- remaining.concat(parser.parse([head]))
- rescue OptionParser::InvalidOption
- remaining << head
- retry
- rescue OptionParser::MissingArgument
- raise ArgumentError, "The option '#{head}' requires an argument."
- rescue OptionParser::AmbiguousOption
- raise ArgumentError, "There is more than one possible option that starts with '#{head}'."
+ !process_arguments([arg]).empty?
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption
+ true
end
end
- # for compat with Homebrew, not certain if this is desirable
- self.verbose = true if ARGV.verbose?
- self.debug = true if ARGV.debug?
-
- remaining
+ remaining + non_options
end
class NullCommand
diff --git a/Library/Homebrew/cask/lib/hbc/cli/--version.rb b/Library/Homebrew/cask/lib/hbc/cli/--version.rb
index bbc719c3b..1833c51c6 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/--version.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/--version.rb
@@ -1,12 +1,17 @@
module Hbc
class CLI
- class Version < Base
+ class Version < AbstractCommand
def self.command_name
"--#{super}"
end
- def self.run(*args)
- raise ArgumentError, "#{command_name} does not take arguments." unless args.empty?
+ def initialize(*)
+ super
+ return if args.empty?
+ raise ArgumentError, "#{self.class.command_name} does not take arguments."
+ end
+
+ def run
puts Hbc.full_version
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
new file mode 100644
index 000000000..cdb7f5ec8
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
@@ -0,0 +1,45 @@
+require_relative "options"
+
+module Hbc
+ class CLI
+ class AbstractCommand
+ include Options
+
+ option "--[no-]binaries", :binaries, true
+ option "--debug", :debug, false
+ option "--verbose", :verbose, false
+ option "--outdated", :outdated_only, false
+
+ def self.command_name
+ @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
+ end
+
+ def self.abstract?
+ name.split("::").last.match?(/^Abstract[^a-z]/)
+ end
+
+ def self.visible
+ true
+ end
+
+ def self.help
+ nil
+ end
+
+ def self.needs_init?
+ false
+ end
+
+ def self.run(*args)
+ new(*args).run
+ end
+
+ attr_accessor :args
+ private :args=
+
+ def initialize(*args)
+ @args = process_arguments(*args)
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb
index b1f9c5631..8af71e589 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_use_base.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_internal_command.rb
@@ -1,6 +1,6 @@
module Hbc
class CLI
- class InternalUseBase < Base
+ class AbstractInternalCommand < AbstractCommand
def self.command_name
super.sub(/^internal_/i, "_")
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
index ec1c33754..74d1ebfa7 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
@@ -1,51 +1,27 @@
module Hbc
class CLI
- class Audit < Base
+ class Audit < AbstractCommand
+ option "--download", :download, false
+ option "--token-conflicts", :token_conflicts, false
+
def self.help
"verifies installability of Casks"
end
- def self.run(*args)
- failed_casks = new(args, Auditor).run
- return if failed_casks.empty?
- raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
- end
-
- def initialize(args, auditor)
- @args = args
- @auditor = auditor
- end
-
def run
- casks_to_audit.each_with_object([]) do |cask, failed|
- failed << cask unless audit(cask)
+ casks_to_audit = args.empty? ? Hbc.all : args.map(&CaskLoader.public_method(:load))
+
+ failed_casks = casks_to_audit.reject do |cask|
+ audit(cask)
end
+
+ return if failed_casks.empty?
+ raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end
def audit(cask)
odebug "Auditing Cask #{cask}"
- @auditor.audit(cask, audit_download: audit_download?,
- check_token_conflicts: check_token_conflicts?)
- end
-
- def audit_download?
- @args.include?("--download")
- end
-
- def check_token_conflicts?
- @args.include?("--token-conflicts")
- end
-
- def casks_to_audit
- if cask_tokens.empty?
- Hbc.all
- else
- cask_tokens.map { |token| CaskLoader.load(token) }
- end
- end
-
- def cask_tokens
- @cask_tokens ||= self.class.cask_tokens_from(@args)
+ Auditor.audit(cask, audit_download: download?, check_token_conflicts: token_conflicts?)
end
def self.needs_init?
diff --git a/Library/Homebrew/cask/lib/hbc/cli/base.rb b/Library/Homebrew/cask/lib/hbc/cli/base.rb
deleted file mode 100644
index 3301cad91..000000000
--- a/Library/Homebrew/cask/lib/hbc/cli/base.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module Hbc
- class CLI
- class Base
- def self.command_name
- @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
- end
-
- def self.visible
- true
- end
-
- def self.cask_tokens_from(args)
- args.reject { |a| a.empty? || a.chars.first == "-" }
- end
-
- def self.help
- nil
- end
-
- def self.needs_init?
- false
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
index 52f6e0eab..e68481b46 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
@@ -1,14 +1,17 @@
module Hbc
class CLI
- class Cat < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- # only respects the first argument
- cask_token = cask_tokens.first.sub(/\.rb$/i, "")
- cask_path = CaskLoader.path(cask_token)
- raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
- puts File.open(cask_path, &:read)
+ class Cat < AbstractCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ args.each do |cask_token|
+ cask_path = CaskLoader.path(cask_token)
+ raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
+ puts File.open(cask_path, &:read)
+ end
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
index 9ebccabd0..40b37dd5d 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
@@ -1,6 +1,6 @@
module Hbc
class CLI
- class Cleanup < Base
+ class Cleanup < AbstractCommand
OUTDATED_DAYS = 10
OUTDATED_TIMESTAMP = Time.now - (60 * 60 * 24 * OUTDATED_DAYS)
@@ -12,30 +12,15 @@ module Hbc
true
end
- def self.run(*args)
- if args.empty?
- default.cleanup!
- else
- default.cleanup(args)
- end
- end
-
- def self.default
- @default ||= new(Hbc.cache, CLI.outdated?)
- end
+ attr_reader :cache_location
- attr_reader :cache_location, :outdated_only
- def initialize(cache_location, outdated_only)
+ def initialize(*args, cache_location: Hbc.cache)
+ super(*args)
@cache_location = Pathname.new(cache_location)
- @outdated_only = outdated_only
- end
-
- def cleanup!
- remove_cache_files
end
- def cleanup(tokens)
- remove_cache_files(*tokens)
+ def run
+ remove_cache_files(*@args)
end
def cache_files
@@ -46,7 +31,7 @@ module Hbc
end
def outdated?(file)
- outdated_only && file && file.stat.mtime > OUTDATED_TIMESTAMP
+ outdated_only? && file && file.stat.mtime > OUTDATED_TIMESTAMP
end
def incomplete?(file)
@@ -68,7 +53,7 @@ module Hbc
def remove_cache_files(*tokens)
message = "Removing cached downloads"
message.concat " for #{tokens.join(", ")}" unless tokens.empty?
- message.concat " older than #{OUTDATED_DAYS} days old" if outdated_only
+ message.concat " older than #{OUTDATED_DAYS} days old" if outdated_only?
ohai message
deletable_cache_files = if tokens.empty?
@@ -90,14 +75,18 @@ module Hbc
paths.each do |item|
next unless item.exist?
processed_files += 1
- if Utils.file_locked?(item)
+
+ begin
+ LockFile.new(item.basename).with_lock do
+ puts item
+ item_size = File.size?(item)
+ cleanup_size += item_size unless item_size.nil?
+ item.unlink
+ end
+ rescue OperationInProgressError
puts "skipping: #{item} is locked"
next
end
- puts item
- item_size = File.size?(item)
- cleanup_size += item_size unless item_size.nil?
- item.unlink
end
if processed_files.zero?
diff --git a/Library/Homebrew/cask/lib/hbc/cli/create.rb b/Library/Homebrew/cask/lib/hbc/cli/create.rb
index 5e143d085..8de101092 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/create.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/create.rb
@@ -1,17 +1,20 @@
module Hbc
class CLI
- class Create < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- cask_token = cask_tokens.first.sub(/\.rb$/i, "")
- cask_path = CaskLoader.path(cask_token)
- odebug "Creating Cask #{cask_token}"
+ class Create < AbstractCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ raise ArgumentError, "Only one Cask can be created at a time." if args.count > 1
+ end
+ def run
+ cask_token = args.first
+ cask_path = CaskLoader.path(cask_token)
raise CaskAlreadyCreatedError, cask_token if cask_path.exist?
+ odebug "Creating Cask #{cask_token}"
File.open(cask_path, "w") do |f|
- f.write template(cask_token)
+ f.write self.class.template(cask_token)
end
exec_editor cask_path
diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
index 031f78824..cd6ebbc12 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
@@ -1,30 +1,36 @@
module Hbc
class CLI
- class Doctor < Base
- def self.run
+ class Doctor < AbstractCommand
+ def initialize(*)
+ super
+ return if args.empty?
+ raise ArgumentError, "#{self.class.command_name} does not take arguments."
+ end
+
+ def run
ohai "Homebrew-Cask Version", Hbc.full_version
- ohai "Homebrew-Cask Install Location", render_install_location
- ohai "Homebrew-Cask Staging Location", render_staging_location(Hbc.caskroom)
- ohai "Homebrew-Cask Cached Downloads", render_cached_downloads
+ ohai "Homebrew-Cask Install Location", self.class.render_install_location
+ ohai "Homebrew-Cask Staging Location", self.class.render_staging_location(Hbc.caskroom)
+ ohai "Homebrew-Cask Cached Downloads", self.class.render_cached_downloads
ohai "Homebrew-Cask Taps:"
- puts render_taps(Hbc.default_tap, *alt_taps)
- ohai "Contents of $LOAD_PATH", render_load_path($LOAD_PATH)
+ puts self.class.render_taps(Hbc.default_tap, *self.class.alt_taps)
+ ohai "Contents of $LOAD_PATH", self.class.render_load_path($LOAD_PATH)
ohai "Environment Variables"
- environment_variables = [
- "RUBYLIB",
- "RUBYOPT",
- "RUBYPATH",
- "RBENV_VERSION",
- "CHRUBY_VERSION",
- "GEM_HOME",
- "GEM_PATH",
- "BUNDLE_PATH",
- "PATH",
- "SHELL",
+ environment_variables = %w[
+ RUBYLIB
+ RUBYOPT
+ RUBYPATH
+ RBENV_VERSION
+ CHRUBY_VERSION
+ GEM_HOME
+ GEM_PATH
+ BUNDLE_PATH
+ PATH
+ SHELL
]
- (locale_variables + environment_variables).sort.each(&method(:render_env_var))
+ (self.class.locale_variables + environment_variables).sort.each(&self.class.method(:render_env_var))
end
def self.locale_variables
@@ -45,12 +51,11 @@ module Hbc
end
def self.alt_taps
- Tap.select { |t| t.cask_dir && t != Hbc.default_tap }
+ Tap.select { |t| t.cask_dir.exist? && t != Hbc.default_tap }
end
def self.cask_count_for_tap(tap)
- count = tap.cask_files.count
- "#{count} #{count == 1 ? "cask" : "casks"}"
+ Formatter.pluralize(tap.cask_files.count, "cask")
rescue StandardError
"0 #{error_string "error reading #{tap.path}"}"
end
@@ -107,7 +112,7 @@ module Hbc
end
def self.render_cached_downloads
- cleanup = CLI::Cleanup.default
+ cleanup = CLI::Cleanup.new
count = cleanup.cache_files.count
size = cleanup.disk_cleanup_size
msg = user_tilde(Hbc.cache.to_s)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
index 1f1e0d918..dec0fe36b 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
@@ -1,16 +1,21 @@
module Hbc
class CLI
- class Edit < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- # only respects the first argument
- cask_token = cask_tokens.first.sub(/\.rb$/i, "")
+ class Edit < AbstractCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ raise ArgumentError, "Only one Cask can be created at a time." if args.count > 1
+ end
+
+ def run
+ cask_token = args.first
cask_path = CaskLoader.path(cask_token)
- odebug "Opening editor for Cask #{cask_token}"
+
unless cask_path.exist?
raise CaskUnavailableError, %Q(#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask)
end
+
+ odebug "Opening editor for Cask #{cask_token}"
exec_editor cask_path
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
index 83dba672c..2c1cc5f66 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
@@ -1,15 +1,18 @@
module Hbc
class CLI
- class Fetch < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- force = args.include? "--force"
+ class Fetch < AbstractCommand
+ option "--force", :force, false
- cask_tokens.each do |cask_token|
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ args.each do |cask_token|
ohai "Downloading external files for Cask #{cask_token}"
cask = CaskLoader.load(cask_token)
- downloaded_path = Download.new(cask, force: force).perform
+ downloaded_path = Download.new(cask, force: force?).perform
Verify.all(cask, downloaded_path)
ohai "Success! Downloaded to -> #{downloaded_path}"
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/home.rb b/Library/Homebrew/cask/lib/hbc/cli/home.rb
index 66be49186..009bc1e3e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/home.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/home.rb
@@ -1,19 +1,24 @@
module Hbc
class CLI
- class Home < Base
- def self.run(*cask_tokens)
- if cask_tokens.empty?
+ class Home < AbstractCommand
+ def run
+ casks = args.map(&CaskLoader.public_method(:load))
+
+ if casks.empty?
odebug "Opening project homepage"
- system "/usr/bin/open", "--", "https://caskroom.github.io/"
+ self.class.open_url "https://caskroom.github.io/"
else
- cask_tokens.each do |cask_token|
- odebug "Opening homepage for Cask #{cask_token}"
- cask = CaskLoader.load(cask_token)
- system "/usr/bin/open", "--", cask.homepage
+ casks.each do |cask|
+ odebug "Opening homepage for Cask #{cask}"
+ self.class.open_url cask.homepage
end
end
end
+ def self.open_url(url)
+ SystemCommand.run!(OS::PATH_OPEN, args: ["--", url])
+ end
+
def self.help
"opens the homepage of the given Cask"
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb
index 625b4ecae..623c4b737 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/info.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -1,14 +1,17 @@
module Hbc
class CLI
- class Info < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- cask_tokens.each do |cask_token|
+ class Info < AbstractCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ args.each do |cask_token|
odebug "Getting info for Cask #{cask_token}"
cask = CaskLoader.load(cask_token)
- info(cask)
+ self.class.info(cask)
end
end
@@ -20,7 +23,7 @@ module Hbc
puts "#{cask.token}: #{cask.version}"
puts Formatter.url(cask.homepage) if cask.homepage
installation_info(cask)
- puts "From: #{Formatter.url(repo_info(cask))}"
+ repo_info(cask)
name_info(cask)
artifact_info(cask)
Installer.print_caveats(cask)
@@ -38,7 +41,7 @@ module Hbc
puts versioned_staged_path.to_s
.concat(" (")
.concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist"))
- .concat(")")
+ .concat(")")
end
else
puts "Not installed"
@@ -46,19 +49,24 @@ module Hbc
end
def self.name_info(cask)
- ohai cask.name.size > 1 ? "Names" : "Name"
+ ohai((cask.name.size > 1) ? "Names" : "Name")
puts cask.name.empty? ? Formatter.error("None") : cask.name
end
def self.repo_info(cask)
user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })
+
+ return if user.nil? || repo.nil?
+
remote_tap = Tap.fetch(user, repo)
- if remote_tap.custom_remote? && !remote_tap.remote.nil?
- return remote_tap.remote.to_s
+ url = if remote_tap.custom_remote? && !remote_tap.remote.nil?
+ remote_tap.remote
+ else
+ "#{remote_tap.default_remote}/blob/master/Casks/#{token}.rb"
end
- "#{remote_tap.default_remote}/blob/master/Casks/#{token}.rb"
+ puts "From: #{Formatter.url(url)}"
end
def self.artifact_info(cask)
@@ -66,7 +74,7 @@ module Hbc
DSL::ORDINARY_ARTIFACT_TYPES.each do |type|
next if cask.artifacts[type].empty?
cask.artifacts[type].each do |artifact|
- activatable_item = type == :stage_only ? "<none>" : artifact.first
+ activatable_item = (type == :stage_only) ? "<none>" : artifact.first
puts "#{activatable_item} (#{type})"
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb
index 438f860c1..72f85fc69 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/install.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -1,28 +1,33 @@
module Hbc
class CLI
- class Install < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- force = args.include? "--force"
- skip_cask_deps = args.include? "--skip-cask-deps"
- require_sha = args.include? "--require-sha"
- retval = install_casks cask_tokens, force, skip_cask_deps, require_sha
+ class Install < AbstractCommand
+ option "--force", :force, false
+ option "--skip-cask-deps", :skip_cask_deps, false
+ option "--require-sha", :require_sha, false
+
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ retval = install_casks
# retval is ternary: true/false/nil
raise CaskError, "nothing to install" if retval.nil?
raise CaskError, "install incomplete" unless retval
end
- def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
+ def install_casks
count = 0
- cask_tokens.each do |cask_token|
+ args.each do |cask_token|
begin
cask = CaskLoader.load(cask_token)
- Installer.new(cask,
- force: force,
- skip_cask_deps: skip_cask_deps,
- require_sha: require_sha).install
+ Installer.new(cask, binaries: binaries?,
+ verbose: verbose?,
+ force: force?,
+ skip_cask_deps: skip_cask_deps?,
+ require_sha: require_sha?).install
count += 1
rescue CaskAlreadyInstalledError => e
opoo e.message
@@ -31,7 +36,7 @@ module Hbc
opoo e.message
count += 1
rescue CaskUnavailableError => e
- warn_unavailable_with_suggestion cask_token, e
+ self.class.warn_unavailable_with_suggestion cask_token, e
rescue CaskNoShasumError => e
opoo e.message
count += 1
@@ -39,7 +44,8 @@ module Hbc
onoe e.message
end
end
- count.zero? ? nil : count == cask_tokens.length
+
+ count.zero? ? nil : count == args.length
end
def self.warn_unavailable_with_suggestion(cask_token, e)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
index da3567108..cd2679782 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
@@ -1,15 +1,18 @@
module Hbc
class CLI
- class InternalAppcastCheckpoint < InternalUseBase
- def self.run(*args)
- calculate = args.include? "--calculate"
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
-
- if cask_tokens.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ }
- appcask_checkpoint_for_url(cask_tokens)
+ class InternalAppcastCheckpoint < AbstractInternalCommand
+ option "--calculate", :calculate, false
+
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ if args.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ }
+ self.class.appcask_checkpoint_for_url(args)
else
- appcask_checkpoint(cask_tokens, calculate)
+ self.class.appcask_checkpoint(args, calculate?)
end
end
@@ -40,7 +43,7 @@ module Hbc
if checkpoint.nil?
onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}"
else
- puts cask_tokens.count > 1 ? "#{checkpoint} #{cask}": checkpoint
+ puts((cask_tokens.count > 1) ? "#{checkpoint} #{cask}" : checkpoint)
count += 1
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
index 9467cccc7..f1a0308e5 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
@@ -1,26 +1,29 @@
module Hbc
class CLI
- class InternalAuditModifiedCasks < InternalUseBase
+ class InternalAuditModifiedCasks < AbstractInternalCommand
RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze
+ option "--cleanup", :cleanup, false
+
def self.needs_init?
true
end
- def self.run(*args)
- commit_range = commit_range(args)
- cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i }
- new(commit_range, cleanup: cleanup).run
- end
+ attr_accessor :commit_range
+ private :commit_range=
- def self.commit_range(args)
- posargs = args.reject { |a| a.empty? || a.chars.first == "-" }
- odie usage unless posargs.size == 1
- posargs.first
- end
+ def initialize(*)
+ super
+
+ if args.count != 1
+ raise ArgumentError, <<-EOS.undent
+ This command requires exactly one argument.
+
+ #{self.class.usage}
+ EOS
+ end
- def self.posargs(args)
- args.reject { |a| a.empty? || a.chars.first == "-" }
+ @commit_range = args.first
end
def self.help
@@ -41,17 +44,6 @@ module Hbc
EOS
end
- def initialize(commit_range, cleanup: false)
- @commit_range = commit_range
- @cleanup = cleanup
- end
-
- attr_reader :commit_range
-
- def cleanup?
- @cleanup
- end
-
def run
at_exit do
cleanup
@@ -97,7 +89,8 @@ module Hbc
audit_download = audit_download?(cask, cask_file)
check_token_conflicts = added_cask_files.include?(cask_file)
success = Auditor.audit(cask, audit_download: audit_download,
- check_token_conflicts: check_token_conflicts)
+ check_token_conflicts: check_token_conflicts,
+ commit_range: commit_range)
failed_casks << cask unless success
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
index b7d95957d..a8c3d5c8f 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
@@ -1,8 +1,8 @@
module Hbc
class CLI
- class InternalCheckurl < InternalUseBase
- def self.run(*args)
- casks_to_check = args.empty? ? Hbc.all : args.map { |arg| CaskLoader.load(arg) }
+ class InternalCheckurl < AbstractInternalCommand
+ def run
+ casks_to_check = args.empty? ? Hbc.all : args.map(&CaskLoader.public_method(:load))
casks_to_check.each do |cask|
odebug "Checking URL for Cask #{cask}"
checker = UrlChecker.new(cask)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
index 8017a32cf..78dbf1622 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
@@ -1,20 +1,22 @@
module Hbc
class CLI
- class InternalDump < InternalUseBase
- def self.run(*arguments)
- cask_tokens = cask_tokens_from(arguments)
- raise CaskUnspecifiedError if cask_tokens.empty?
- retval = dump_casks(*cask_tokens)
+ class InternalDump < AbstractInternalCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ retval = dump_casks
# retval is ternary: true/false/nil
raise CaskError, "nothing to dump" if retval.nil?
raise CaskError, "dump incomplete" unless retval
end
- def self.dump_casks(*cask_tokens)
- CLI.debug = true # Yuck. At the moment this is the only way to make dumps visible
+ def dump_casks
count = 0
- cask_tokens.each do |cask_token|
+ args.each do |cask_token|
begin
cask = CaskLoader.load(cask_token)
count += 1
@@ -23,7 +25,7 @@ module Hbc
opoo "#{cask_token} was not found or would not load: #{e}"
end
end
- count.zero? ? nil : count == cask_tokens.length
+ count.zero? ? nil : count == args.length
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb
index 0908ee05e..beac77b29 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_help.rb
@@ -1,12 +1,18 @@
module Hbc
class CLI
- class InternalHelp < InternalUseBase
- def self.run(*_ignored)
+ class InternalHelp < AbstractInternalCommand
+ def initialize(*)
+ super
+ return if args.empty?
+ raise ArgumentError, "#{self.class.command_name} does not take arguments."
+ end
+
+ def run
max_command_len = CLI.commands.map(&:length).max
puts "Unstable Internal-use Commands:\n\n"
CLI.command_classes.each do |klass|
next if klass.visible
- puts " #{klass.command_name.ljust(max_command_len)} #{help_for(klass)}"
+ puts " #{klass.command_name.ljust(max_command_len)} #{self.class.help_for(klass)}"
end
puts "\n"
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
index 303aa7ffe..86dee7c9c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
@@ -1,6 +1,6 @@
module Hbc
class CLI
- class InternalStanza < InternalUseBase
+ class InternalStanza < AbstractInternalCommand
# Syntax
#
# brew cask _stanza <stanza_name> [ --table | --yaml | --inspect | --quiet ] [ <cask_token> ... ]
@@ -50,71 +50,82 @@ module Hbc
:uninstall_postflight,
]
- def self.run(*args)
+ option "--table", :table, false
+ option "--quiet", :quiet, false
+ option "--yaml", :yaml, false
+ option "--inspect", :inspect, false
+
+ attr_accessor :format
+ private :format, :format=
+
+ attr_accessor :stanza
+ private :stanza, :stanza=
+
+ def initialize(*)
+ super
raise ArgumentError, "No stanza given." if args.empty?
- table = args.include? "--table"
- quiet = args.include? "--quiet"
- format = :to_yaml if args.include? "--yaml"
- format = :inspect if args.include? "--inspect"
- cask_tokens = cask_tokens_from(args)
- stanza = cask_tokens.shift.to_sym
- cask_tokens = Hbc.all_tokens if cask_tokens.empty?
+ @stanza = args.shift.to_sym
- retval = print_stanzas(stanza, format, table, quiet, *cask_tokens)
+ @format = :to_yaml if yaml?
+ @format = :inspect if inspect?
+ end
+ def run
+ retval = print_stanzas
# retval is ternary: true/false/nil
if retval.nil?
- exit 1 if quiet
+ exit 1 if quiet?
raise CaskError, "nothing to print"
elsif !retval
- exit 1 if quiet
+ exit 1 if quiet?
raise CaskError, "print incomplete"
end
end
- def self.print_stanzas(stanza, format = nil, table = nil, quiet = nil, *cask_tokens)
+ def print_stanzas
count = 0
if ARTIFACTS.include?(stanza)
artifact_name = stanza
- stanza = :artifacts
+ @stanza = :artifacts
end
+ cask_tokens = args.empty? ? Hbc.all_tokens : args
cask_tokens.each do |cask_token|
- print "#{cask_token}\t" if table
+ print "#{cask_token}\t" if table?
begin
cask = CaskLoader.load(cask_token)
rescue StandardError
- opoo "Cask '#{cask_token}' was not found" unless quiet
+ opoo "Cask '#{cask_token}' was not found" unless quiet?
puts ""
next
end
unless cask.respond_to?(stanza)
- opoo "no such stanza '#{stanza}' on Cask '#{cask_token}'" unless quiet
+ opoo "no such stanza '#{stanza}' on Cask '#{cask_token}'" unless quiet?
puts ""
next
end
begin
- value = cask.send(stanza)
+ value = cask.send(@stanza)
rescue StandardError
- opoo "failure calling '#{stanza}' on Cask '#{cask_token}'" unless quiet
+ opoo "failure calling '#{stanza}' on Cask '#{cask_token}'" unless quiet?
puts ""
next
end
if artifact_name && !value.key?(artifact_name)
- opoo "no such stanza '#{artifact_name}' on Cask '#{cask_token}'" unless quiet
+ opoo "no such stanza '#{artifact_name}' on Cask '#{cask_token}'" unless quiet?
puts ""
next
end
value = value.fetch(artifact_name).to_a.flatten if artifact_name
- if format
- puts value.send(format)
+ if @format
+ puts value.send(@format)
elsif artifact_name || value.is_a?(Symbol)
puts value.inspect
else
diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb
index d9bf2187b..9d2ded4be 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/list.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb
@@ -1,19 +1,18 @@
module Hbc
class CLI
- class List < Base
- def self.run(*arguments)
- @options = {}
- @options[:one] = true if arguments.delete("-1")
- @options[:versions] = true if arguments.delete("--versions")
+ class List < AbstractCommand
+ option "-1", :one, false
+ option "--versions", :versions, false
- if arguments.delete("-l")
- @options[:one] = true
- opoo "Option -l is obsolete! Implying option -1."
- end
+ option "-l", (lambda do |*|
+ one = true # rubocop:disable Lint/UselessAssignment
+ opoo "Option -l is obsolete! Implying option -1."
+ end)
- retval = arguments.any? ? list(*arguments) : list_installed
+ def run
+ retval = args.any? ? list : list_installed
# retval is ternary: true/false/nil
- if retval.nil? && !arguments.any?
+ if retval.nil? && args.none?
opoo "nothing to list" # special case: avoid exit code
elsif retval.nil?
raise CaskError, "nothing to list"
@@ -22,22 +21,22 @@ module Hbc
end
end
- def self.list(*cask_tokens)
+ def list
count = 0
- cask_tokens.each do |cask_token|
+ args.each do |cask_token|
odebug "Listing files for Cask #{cask_token}"
begin
cask = CaskLoader.load(cask_token)
if cask.installed?
- if @options[:one]
+ if one?
puts cask.token
- elsif @options[:versions]
- puts format_versioned(cask)
+ elsif versions?
+ puts self.class.format_versioned(cask)
else
cask = CaskLoader.load_from_file(cask.installed_caskfile)
- list_artifacts(cask)
+ self.class.list_artifacts(cask)
end
count += 1
@@ -49,7 +48,7 @@ module Hbc
end
end
- count.zero? ? nil : count == cask_tokens.length
+ count.zero? ? nil : count == args.length
end
def self.list_artifacts(cask)
@@ -59,13 +58,13 @@ module Hbc
end
end
- def self.list_installed
+ def list_installed
installed_casks = Hbc.installed
- if @options[:one]
+ if one?
puts installed_casks.map(&:to_s)
- elsif @options[:versions]
- puts installed_casks.map(&method(:format_versioned))
+ elsif versions?
+ puts installed_casks.map(&self.class.method(:format_versioned))
elsif !installed_casks.empty?
puts Formatter.columns(installed_casks.map(&:to_s))
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/options.rb b/Library/Homebrew/cask/lib/hbc/cli/options.rb
new file mode 100644
index 000000000..75dd77212
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/options.rb
@@ -0,0 +1,64 @@
+module Hbc
+ class CLI
+ module Options
+ def self.included(klass)
+ klass.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def options
+ @options ||= {}
+ return @options unless superclass.respond_to?(:options)
+ superclass.options.merge(@options)
+ end
+
+ def option(name, method, default_value = nil)
+ @options ||= {}
+ @options[name] = method
+
+ return if method.respond_to?(:call)
+
+ define_method(:"#{method}=") do |value|
+ instance_variable_set(:"@#{method}", value)
+ end
+
+ if [true, false].include?(default_value)
+ define_method(:"#{method}?") do
+ return default_value unless instance_variable_defined?(:"@#{method}")
+ instance_variable_get(:"@#{method}") == true
+ end
+ else
+ define_method(:"#{method}") do
+ return default_value unless instance_variable_defined?(:"@#{method}")
+ instance_variable_get(:"@#{method}")
+ end
+ end
+ end
+ end
+
+ def process_arguments(*arguments)
+ parser = OptionParser.new do |opts|
+ next if self.class.options.nil?
+
+ self.class.options.each do |option_name, option_method|
+ option_type = case option_name.split(/(\ |\=)/).last
+ when "PATH"
+ Pathname
+ when /\w+(,\w+)+/
+ Array
+ end
+
+ opts.on(option_name, *option_type) do |value|
+ if option_method.respond_to?(:call)
+ option_method.call(value)
+ else
+ send(:"#{option_method}=", value)
+ end
+ end
+ end
+ end
+ parser.parse(*arguments)
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
index 5956f59ac..7877ead05 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
@@ -1,20 +1,20 @@
module Hbc
class CLI
- class Outdated < Base
- def self.run(*args)
- greedy = args.include?("--greedy")
- verbose = ($stdout.tty? || CLI.verbose?) && !args.include?("--quiet")
+ class Outdated < AbstractCommand
+ option "--greedy", :greedy, false
+ option "--quiet", :quiet, false
- cask_tokens = cask_tokens_from(args)
- casks_to_check = if cask_tokens.empty?
- Hbc.installed
- else
- cask_tokens.map { |token| CaskLoader.load(token) }
- end
+ def initialize(*)
+ super
+ self.verbose = ($stdout.tty? || verbose?) && !quiet?
+ end
+
+ def run
+ casks_to_check = args.empty? ? Hbc.installed : args.map(&CaskLoader.public_method(:load))
casks_to_check.each do |cask|
odebug "Checking update info of Cask #{cask}"
- list_if_outdated(cask, greedy, verbose)
+ self.class.list_if_outdated(cask, greedy?, verbose?)
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
index c2ed8f462..eb5f45c90 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -1,26 +1,29 @@
module Hbc
class CLI
class Reinstall < Install
- def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
+ def install_casks
count = 0
- cask_tokens.each do |cask_token|
+ args.each do |cask_token|
begin
cask = CaskLoader.load(cask_token)
Installer.new(cask,
- force: force,
- skip_cask_deps: skip_cask_deps,
- require_sha: require_sha).reinstall
+ binaries: binaries?,
+ verbose: verbose?,
+ force: force?,
+ skip_cask_deps: skip_cask_deps?,
+ require_sha: require_sha?).reinstall
count += 1
rescue CaskUnavailableError => e
- warn_unavailable_with_suggestion cask_token, e
+ self.class.warn_unavailable_with_suggestion cask_token, e
rescue CaskNoShasumError => e
opoo e.message
count += 1
end
end
- count.zero? ? nil : count == cask_tokens.length
+
+ count.zero? ? nil : count == args.length
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb
index 7abd744e4..b24091aef 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/search.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb
@@ -1,8 +1,13 @@
module Hbc
class CLI
- class Search < Base
- def self.run(*arguments)
- render_results(*search(*arguments))
+ class Search < AbstractCommand
+ def initialize(*args)
+ @args = args
+ end
+
+ def run
+ results = self.class.search(*args)
+ self.class.render_results(*results)
end
def self.extract_regexp(string)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index 191aefd3c..97208232b 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -2,25 +2,19 @@ require "English"
module Hbc
class CLI
- class Style < Base
+ class Style < AbstractCommand
def self.help
"checks Cask style using RuboCop"
end
- def self.run(*args)
- retval = new(args).run
- raise CaskError, "style check failed" unless retval
- end
-
- attr_reader :args
- def initialize(args)
- @args = args
- end
+ option "--fix", :fix, false
def run
install_rubocop
- system "rubocop", *rubocop_args, "--", *cask_paths
- $CHILD_STATUS.success?
+ cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
+ system(cache_env, "rubocop", *rubocop_args, "--", *cask_paths)
+ raise CaskError, "style check failed" unless $CHILD_STATUS.success?
+ true
end
def install_rubocop
@@ -34,19 +28,15 @@ module Hbc
end
def cask_paths
- @cask_paths ||= if cask_tokens.empty?
+ @cask_paths ||= if args.empty?
Hbc.all_tapped_cask_dirs
- elsif cask_tokens.any? { |file| File.exist?(file) }
- cask_tokens
+ elsif args.any? { |file| File.exist?(file) }
+ args
else
- cask_tokens.map { |token| CaskLoader.path(token) }
+ args.map { |token| CaskLoader.path(token) }
end
end
- def cask_tokens
- @cask_tokens ||= self.class.cask_tokens_from(args)
- end
-
def rubocop_args
fix? ? autocorrect_args : default_args
end
@@ -63,10 +53,6 @@ module Hbc
def autocorrect_args
default_args + ["--auto-correct"]
end
-
- def fix?
- args.any? { |arg| arg =~ /--(fix|(auto-?)?correct)/ }
- end
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
index 1ee3230ad..33ee5afa9 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
@@ -1,23 +1,26 @@
module Hbc
class CLI
- class Uninstall < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- force = args.include? "--force"
+ class Uninstall < AbstractCommand
+ option "--force", :force, false
- cask_tokens.each do |cask_token|
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ args.each do |cask_token|
odebug "Uninstalling Cask #{cask_token}"
cask = CaskLoader.load(cask_token)
- raise CaskNotInstalledError, cask unless cask.installed? || force
+ raise CaskNotInstalledError, cask unless cask.installed? || force?
if cask.installed? && !cask.installed_caskfile.nil?
# use the same cask file that was used for installation, if possible
cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist?
end
- Installer.new(cask, force: force).uninstall
+ Installer.new(cask, binaries: binaries?, verbose: verbose?, force: force?).uninstall
next if (versions = cask.versions).empty?
diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
index 83da1c932..3c07ff9e8 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
@@ -1,13 +1,16 @@
module Hbc
class CLI
- class Zap < Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise CaskUnspecifiedError if cask_tokens.empty?
- cask_tokens.each do |cask_token|
+ class Zap < AbstractCommand
+ def initialize(*)
+ super
+ raise CaskUnspecifiedError if args.empty?
+ end
+
+ def run
+ args.each do |cask_token|
odebug "Zapping Cask #{cask_token}"
cask = CaskLoader.load(cask_token)
- Installer.new(cask).zap
+ Installer.new(cask, verbose: verbose?).zap
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb
index 961e31968..93e825e03 100644
--- a/Library/Homebrew/cask/lib/hbc/container.rb
+++ b/Library/Homebrew/cask/lib/hbc/container.rb
@@ -6,6 +6,7 @@ require "hbc/container/criteria"
require "hbc/container/dmg"
require "hbc/container/executable"
require "hbc/container/generic_unar"
+require "hbc/container/gpg"
require "hbc/container/gzip"
require "hbc/container/lzma"
require "hbc/container/naked"
@@ -40,6 +41,7 @@ module Hbc
Gzip, # pure gzip
Lzma, # pure lzma
Xz, # pure xz
+ Gpg, # GnuPG signed data
Executable,
]
# for explicit use only (never autodetected):
diff --git a/Library/Homebrew/cask/lib/hbc/container/cab.rb b/Library/Homebrew/cask/lib/hbc/container/cab.rb
index b3cf01452..010fccbc4 100644
--- a/Library/Homebrew/cask/lib/hbc/container/cab.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/cab.rb
@@ -6,11 +6,7 @@ module Hbc
class Container
class Cab < Base
def self.me?(criteria)
- cabextract = which("cabextract")
-
- criteria.magic_number(/^(MSCF|MZ)/n) &&
- !cabextract.nil? &&
- criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty?
+ criteria.magic_number(/^(MSCF|MZ)/n)
end
def extract
diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
index 1b96df4ec..113c6fb11 100644
--- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
@@ -86,7 +86,7 @@ module Hbc
Dir.chdir(mount) do
Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
next if skip_path?(Pathname(path))
- path == "." ? path : path.prepend("./")
+ (path == ".") ? path : path.prepend("./")
end.compact.join("\n").concat("\n")
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb
new file mode 100644
index 000000000..3f37b5aa6
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb
@@ -0,0 +1,41 @@
+require "tmpdir"
+
+require "hbc/container/base"
+
+module Hbc
+ class Container
+ class Gpg < Base
+ def self.me?(criteria)
+ criteria.extension(/^(gpg)$/)
+ end
+
+ def import_key
+ if @cask.gpg.nil?
+ raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: 'gpg :embedded, key_id: [Public Key ID]' or 'gpg :embedded, key_url: [Public Key URL]'"
+ end
+
+ args = if @cask.gpg.key_id
+ ["--recv-keys", @cask.gpg.key_id]
+ elsif @cask.gpg.key_url
+ ["--fetch-key", @cask.gpg.key_url.to_s]
+ end
+
+ @command.run!("gpg", args: args)
+ end
+
+ def extract
+ if (gpg = which("gpg")).nil?
+ raise CaskError, "Expected to find gpg executable. Cask '#{@cask}' must add: depends_on formula: 'gpg'"
+ end
+
+ import_key
+
+ Dir.mktmpdir do |unpack_dir|
+ @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(@path.basename(".gpg")), "--decrypt", @path])
+
+ extract_nested_inside(unpack_dir)
+ end
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb
index 137af319a..5b32b4840 100644
--- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb
+++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb
@@ -82,10 +82,16 @@ module Hbc
end
def clear_cache
- [cached_location, temporary_path].each do |f|
- next unless f.exist?
- raise CurlDownloadStrategyError, "#{f} is in use by another process" if Utils.file_locked?(f)
- f.unlink
+ [cached_location, temporary_path].each do |path|
+ next unless path.exist?
+
+ begin
+ LockFile.new(path.basename).with_lock do
+ path.unlink
+ end
+ rescue OperationInProgressError
+ raise CurlDownloadStrategyError, "#{path} is in use by another process"
+ end
end
end
@@ -105,10 +111,8 @@ module Hbc
else
had_incomplete_download = temporary_path.exist?
begin
- File.open(temporary_path, "a+") do |f|
- f.flock(File::LOCK_EX)
+ LockFile.new(temporary_path.basename).with_lock do
_fetch
- f.flock(File::LOCK_UN)
end
rescue ErrorDuringExecution
# 33 == range not supported
@@ -208,11 +212,11 @@ module Hbc
class SubversionDownloadStrategy < HbVCSDownloadStrategy
def cache_tag
# TODO: pass versions as symbols, support :head here
- version == "head" ? "svn-HEAD" : "svn"
+ (version == "head") ? "svn-HEAD" : "svn"
end
def repo_valid?
- @clone.join(".svn").directory?
+ (@clone/".svn").directory?
end
def repo_url
diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb
index 4707ae76a..92245e8fb 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -119,9 +119,7 @@ module Hbc
def language_eval
return @language if instance_variable_defined?(:@language)
- if @language_blocks.nil? || @language_blocks.empty?
- return @language = nil
- end
+ return @language = nil if @language_blocks.nil? || @language_blocks.empty?
MacOS.languages.map(&Locale.method(:parse)).each do |locale|
key = @language_blocks.keys.detect do |strings|
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
index e27870622..d302d0946 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
@@ -12,7 +12,7 @@ module Hbc
end
def calculate_checkpoint
- result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, @uri], print_stderr: false)
+ result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false)
checkpoint = if result.success?
processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}m, "")
diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb
index 14c52e94b..b9d305a9b 100644
--- a/Library/Homebrew/cask/lib/hbc/exceptions.rb
+++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb
@@ -113,7 +113,7 @@ module Hbc
end
def to_s
- "Cask '#{token}' definition is invalid" + (!submsg.empty? ? ": #{submsg}" : "")
+ "Cask '#{token}' definition is invalid#{": #{submsg}" unless submsg.empty?}"
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index f02f07806..7da9731e5 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -14,19 +14,35 @@ module Hbc
include Staged
include Verify
- attr_reader :force, :skip_cask_deps
-
PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze
- def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false)
+ def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, binaries: true, verbose: false, require_sha: false)
@cask = cask
@command = command
@force = force
@skip_cask_deps = skip_cask_deps
+ @binaries = binaries
+ @verbose = verbose
@require_sha = require_sha
@reinstall = false
end
+ def skip_cask_deps?
+ @skip_cask_deps
+ end
+
+ def force?
+ @force
+ end
+
+ def binaries?
+ @binaries
+ end
+
+ def verbose?
+ @verbose
+ end
+
def self.print_caveats(cask)
odebug "Printing caveats"
return if cask.caveats.empty?
@@ -59,7 +75,7 @@ module Hbc
odebug "Hbc::Installer#fetch"
satisfy_dependencies
- verify_has_sha if @require_sha && !@force
+ verify_has_sha if @require_sha && !force?
download
verify
end
@@ -77,7 +93,7 @@ module Hbc
def install
odebug "Hbc::Installer#install"
- if @cask.installed? && !force && !@reinstall
+ if @cask.installed? && !force? && !@reinstall
raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates
raise CaskAlreadyInstalledError, @cask
end
@@ -108,7 +124,7 @@ module Hbc
installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask
# Always force uninstallation, ignore method parameter
- Installer.new(installed_cask, force: true).uninstall
+ Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true).uninstall
end
def summary
@@ -156,12 +172,17 @@ module Hbc
already_installed_artifacts = []
odebug "Installing artifacts"
- artifacts = Artifact.for_cask(@cask, command: @command, force: force)
+ artifacts = Artifact.for_cask(@cask, command: @command, verbose: verbose?, force: force?)
odebug "#{artifacts.length} artifact/s defined", artifacts
artifacts.each do |artifact|
next unless artifact.respond_to?(:install_phase)
odebug "Installing artifact of class #{artifact.class}"
+
+ if artifact.is_a?(Artifact::Binary)
+ next unless binaries?
+ end
+
artifact.install_phase
already_installed_artifacts.unshift(artifact)
end
@@ -189,7 +210,7 @@ module Hbc
arch_dependencies
x11_dependencies
formula_dependencies
- cask_dependencies unless skip_cask_deps
+ cask_dependencies unless skip_cask_deps?
puts "complete"
end
@@ -254,7 +275,7 @@ module Hbc
if dep.installed?
puts "already installed"
else
- Installer.new(dep, force: false, skip_cask_deps: true).install
+ Installer.new(dep, binaries: binaries?, verbose: verbose?, skip_cask_deps: true, force: false).install
puts "done"
end
end
@@ -330,16 +351,12 @@ module Hbc
disable_accessibility_access
uninstall_artifacts
purge_versioned_files
- purge_caskroom_path if force
+ purge_caskroom_path if force?
end
def uninstall_artifacts
odebug "Un-installing artifacts"
- artifacts = Artifact.for_cask(@cask, command: @command, force: force)
-
- # Make sure the `uninstall` stanza is run first, as it
- # may depend on other artifacts still being installed.
- artifacts = artifacts.sort_by { |a| a.is_a?(Artifact::Uninstall) ? -1 : 1 }
+ artifacts = Artifact.for_cask(@cask, command: @command, verbose: verbose?, force: force?)
odebug "#{artifacts.length} artifact/s defined", artifacts
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index c14079bc8..6414a9e80 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -94,7 +94,7 @@ module Hbc
loop do
readable_sources = IO.select(sources)[0]
readable_sources.delete_if(&:eof?).first(1).each do |source|
- type = (source == sources[0] ? :stdout : :stderr)
+ type = ((source == sources[0]) ? :stdout : :stderr)
begin
yield(type, source.readline_nonblock || "")
rescue IO::WaitReadable, EOFError
@@ -154,7 +154,7 @@ module Hbc
def self._parse_plist(command, output)
raise CaskError, "Empty plist input" unless output =~ /\S/
output.sub!(/\A(.*?)(<\?\s*xml)/m, '\2')
- _warn_plist_garbage(command, Regexp.last_match[1]) if CLI.debug?
+ _warn_plist_garbage(command, Regexp.last_match[1]) if ARGV.debug?
output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
_warn_plist_garbage(command, Regexp.last_match[2])
xml = Plist.parse_xml(output)
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index b2b65a08e..59e85aaeb 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -2,8 +2,6 @@ require "yaml"
require "open3"
require "stringio"
-require "hbc/utils/file"
-
BUG_REPORTS_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs".freeze
# monkeypatch Object - not a great idea
@@ -29,7 +27,7 @@ end
# global methods
def odebug(title, *sput)
- return unless Hbc::CLI.debug?
+ return unless ARGV.debug?
puts Formatter.headline(title, color: :magenta)
puts sput unless sput.empty?
end
diff --git a/Library/Homebrew/cask/lib/hbc/utils/file.rb b/Library/Homebrew/cask/lib/hbc/utils/file.rb
deleted file mode 100644
index 6b80f33ce..000000000
--- a/Library/Homebrew/cask/lib/hbc/utils/file.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module Hbc
- module Utils
- module_function
-
- def file_locked?(file)
- unlocked = File.open(file).flock(File::LOCK_EX | File::LOCK_NB)
- # revert lock if file was unlocked before check
- File.open(file).flock(File::LOCK_UN) if unlocked
- !unlocked
- rescue
- true
- end
- end
-end