aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb38
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/audit.rb7
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cat.rb10
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cleanup.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/edit.rb10
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/fetch.rb9
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/home.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/info.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/install.rb39
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb18
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb35
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/list.rb44
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/outdated.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/reinstall.rb27
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/search.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/uninstall.rb13
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/zap.rb9
18 files changed, 108 insertions, 175 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
index cdb7f5ec8..77f85301e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb
@@ -9,6 +9,7 @@ module Hbc
option "--debug", :debug, false
option "--verbose", :verbose, false
option "--outdated", :outdated_only, false
+ option "--require-sha", :require_sha, false
def self.command_name
@command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
@@ -40,6 +41,43 @@ module Hbc
def initialize(*args)
@args = process_arguments(*args)
end
+
+ def self.warn_unavailable_with_suggestion(cask_token, e)
+ exact_match, partial_matches = Search.search(cask_token)
+ error_message = e.message
+ if exact_match
+ error_message.concat(" Did you mean:\n#{exact_match}")
+ elsif !partial_matches.empty?
+ error_message.concat(" Did you mean one of:\n")
+ .concat(Formatter.columns(partial_matches.take(20)))
+ end
+ onoe error_message
+ end
+
+ private
+
+ def casks(alternative: -> { [] })
+ return to_enum(:casks, alternative: alternative) unless block_given?
+
+ count = 0
+
+ casks = args.empty? ? alternative.call : args
+
+ casks.each do |cask_or_token|
+ begin
+ yield cask_or_token.respond_to?(:token) ? cask_or_token : CaskLoader.load(cask_or_token)
+ count += 1
+ rescue CaskUnavailableError => e
+ cask_token = cask_or_token
+ self.class.warn_unavailable_with_suggestion cask_token, e
+ rescue CaskError => e
+ onoe e.message
+ end
+ end
+
+ return :empty if casks.length.zero?
+ (count == casks.length) ? :complete : :incomplete
+ end
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
index 74d1ebfa7..35d82800c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
@@ -9,11 +9,8 @@ module Hbc
end
def run
- casks_to_audit = args.empty? ? Hbc.all : args.map(&CaskLoader.public_method(:load))
-
- failed_casks = casks_to_audit.reject do |cask|
- audit(cask)
- end
+ failed_casks = casks(alternative: -> { Hbc.all })
+ .reject { |cask| audit(cask) }
return if failed_casks.empty?
raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
index e68481b46..d08c87bea 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
@@ -7,10 +7,12 @@ module Hbc
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)
+ raise CaskError, "Cat incomplete." if cat_casks == :incomplete
+ end
+
+ def cat_casks
+ casks.each do |cask|
+ puts File.open(cask.sourcefile_path, &:read)
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
index 40b37dd5d..356162db5 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
@@ -20,7 +20,7 @@ module Hbc
end
def run
- remove_cache_files(*@args)
+ remove_cache_files(*args)
end
def cache_files
diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
index dec0fe36b..b9485886c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
@@ -9,10 +9,12 @@ module Hbc
def run
cask_token = args.first
- cask_path = CaskLoader.path(cask_token)
-
- unless cask_path.exist?
- raise CaskUnavailableError, %Q(#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask)
+ cask_path = begin
+ CaskLoader.load(cask_token).sourcefile_path
+ rescue CaskUnavailableError => e
+ reason = e.reason.empty? ? "" : "#{e.reason} "
+ reason.concat("Run #{Formatter.identifier("brew cask create #{e.token}")} to create a new Cask.")
+ raise e.class.new(e.token, reason)
end
odebug "Opening editor for Cask #{cask_token}"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
index 2c1cc5f66..e31b1a17c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
@@ -9,9 +9,12 @@ module Hbc
end
def run
- args.each do |cask_token|
- ohai "Downloading external files for Cask #{cask_token}"
- cask = CaskLoader.load(cask_token)
+ raise CaskError, "Fetch incomplete." if fetch_casks == :incomplete
+ end
+
+ def fetch_casks
+ casks.each do |cask|
+ ohai "Downloading external files for Cask #{cask}"
downloaded_path = Download.new(cask, force: force?).perform
Verify.all(cask, downloaded_path)
ohai "Success! Downloaded to -> #{downloaded_path}"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/home.rb b/Library/Homebrew/cask/lib/hbc/cli/home.rb
index 009bc1e3e..d496e309e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/home.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/home.rb
@@ -2,9 +2,7 @@ module Hbc
class CLI
class Home < AbstractCommand
def run
- casks = args.map(&CaskLoader.public_method(:load))
-
- if casks.empty?
+ if casks.none?
odebug "Opening project homepage"
self.class.open_url "https://caskroom.github.io/"
else
diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb
index 623c4b737..d26747e17 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/info.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -7,10 +7,8 @@ module Hbc
end
def run
- args.each do |cask_token|
- odebug "Getting info for Cask #{cask_token}"
- cask = CaskLoader.load(cask_token)
-
+ casks.each do |cask|
+ odebug "Getting info for Cask #{cask}"
self.class.info(cask)
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb
index 72f85fc69..0f1a5dd34 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/install.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -3,7 +3,6 @@ module Hbc
class Install < AbstractCommand
option "--force", :force, false
option "--skip-cask-deps", :skip_cask_deps, false
- option "--require-sha", :require_sha, false
def initialize(*)
super
@@ -11,53 +10,21 @@ module Hbc
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
+ raise CaskError, "Install incomplete." if install_casks == :incomplete
end
def install_casks
- count = 0
- args.each do |cask_token|
+ casks.each do |cask|
begin
- cask = CaskLoader.load(cask_token)
Installer.new(cask, binaries: binaries?,
- verbose: verbose?,
+ verbose: verbose?,
force: force?,
skip_cask_deps: skip_cask_deps?,
require_sha: require_sha?).install
- count += 1
rescue CaskAlreadyInstalledError => e
opoo e.message
- count += 1
- rescue CaskAlreadyInstalledAutoUpdatesError => e
- opoo e.message
- count += 1
- rescue CaskUnavailableError => e
- self.class.warn_unavailable_with_suggestion cask_token, e
- rescue CaskNoShasumError => e
- opoo e.message
- count += 1
- rescue CaskError => e
- onoe e.message
end
end
-
- count.zero? ? nil : count == args.length
- end
-
- def self.warn_unavailable_with_suggestion(cask_token, e)
- exact_match, partial_matches = Search.search(cask_token)
- error_message = e.message
- if exact_match
- error_message.concat(". Did you mean:\n#{exact_match}")
- elsif !partial_matches.empty?
- error_message.concat(". Did you mean one of:\n")
- .concat(Formatter.columns(partial_matches.take(20)))
- end
- onoe error_message
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
index 78dbf1622..e21ce86b6 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
@@ -7,25 +7,11 @@ module Hbc
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
+ raise CaskError, "Dump incomplete." if dump_casks == :incomplet
end
def dump_casks
- count = 0
- args.each do |cask_token|
- begin
- cask = CaskLoader.load(cask_token)
- count += 1
- cask.dumpcask
- rescue StandardError => e
- opoo "#{cask_token} was not found or would not load: #{e}"
- end
- end
- count.zero? ? nil : count == args.length
+ casks.each(&:dumpcask)
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
index 86dee7c9c..4515fe931 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
@@ -72,38 +72,22 @@ module Hbc
end
def run
- retval = print_stanzas
- # retval is ternary: true/false/nil
- if retval.nil?
- exit 1 if quiet?
- raise CaskError, "nothing to print"
- elsif !retval
- exit 1 if quiet?
- raise CaskError, "print incomplete"
- end
+ return unless print_stanzas == :incomplete
+ exit 1 if quiet?
+ raise CaskError, "Print incomplete."
end
def print_stanzas
- count = 0
if ARTIFACTS.include?(stanza)
artifact_name = stanza
@stanza = :artifacts
end
- cask_tokens = args.empty? ? Hbc.all_tokens : args
- cask_tokens.each do |cask_token|
- print "#{cask_token}\t" if table?
-
- begin
- cask = CaskLoader.load(cask_token)
- rescue StandardError
- opoo "Cask '#{cask_token}' was not found" unless quiet?
- puts ""
- next
- end
+ casks(alternative: -> { Hbc.all }).each do |cask|
+ print "#{cask}\t" if table?
unless cask.respond_to?(stanza)
- opoo "no such stanza '#{stanza}' on Cask '#{cask_token}'" unless quiet?
+ opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet?
puts ""
next
end
@@ -111,13 +95,13 @@ module Hbc
begin
value = cask.send(@stanza)
rescue StandardError
- opoo "failure calling '#{stanza}' on Cask '#{cask_token}'" unless quiet?
+ opoo "failure calling '#{stanza}' on Cask '#{cask}'" 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}'" unless quiet?
puts ""
next
end
@@ -131,10 +115,7 @@ module Hbc
else
puts value.to_s
end
-
- count += 1
end
- count.zero? ? nil : count == cask_tokens.length
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb
index 9d2ded4be..9d978360e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/list.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb
@@ -11,44 +11,22 @@ module Hbc
def run
retval = args.any? ? list : list_installed
- # retval is ternary: true/false/nil
- if retval.nil? && args.none?
- opoo "nothing to list" # special case: avoid exit code
- elsif retval.nil?
- raise CaskError, "nothing to list"
- elsif !retval
- raise CaskError, "listing incomplete"
- end
+ raise CaskError, "Listing incomplete." if retval == :incomplete
end
def list
- count = 0
-
- args.each do |cask_token|
- odebug "Listing files for Cask #{cask_token}"
- begin
- cask = CaskLoader.load(cask_token)
+ casks.each do |cask|
+ raise CaskNotInstalledError, cask unless cask.installed?
- if cask.installed?
- if one?
- puts cask.token
- elsif versions?
- puts self.class.format_versioned(cask)
- else
- cask = CaskLoader.load_from_file(cask.installed_caskfile)
- self.class.list_artifacts(cask)
- end
-
- count += 1
- else
- opoo "#{cask} is not installed"
- end
- rescue CaskUnavailableError => e
- onoe e
+ if one?
+ puts cask.token
+ elsif versions?
+ puts self.class.format_versioned(cask)
+ else
+ cask = CaskLoader.load_from_file(cask.installed_caskfile)
+ self.class.list_artifacts(cask)
end
end
-
- count.zero? ? nil : count == args.length
end
def self.list_artifacts(cask)
@@ -69,7 +47,7 @@ module Hbc
puts Formatter.columns(installed_casks.map(&:to_s))
end
- installed_casks.empty? ? nil : true
+ installed_casks.empty? ? :empty : :complete
end
def self.format_versioned(cask)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
index 7877ead05..b0a84e8d2 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
@@ -10,9 +10,7 @@ module Hbc
end
def run
- casks_to_check = args.empty? ? Hbc.installed : args.map(&CaskLoader.public_method(:load))
-
- casks_to_check.each do |cask|
+ casks(alternative: -> { Hbc.installed }).each do |cask|
odebug "Checking update info of Cask #{cask}"
self.class.list_if_outdated(cask, greedy?, verbose?)
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
index eb5f45c90..337a2eb9d 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -2,28 +2,13 @@ module Hbc
class CLI
class Reinstall < Install
def install_casks
- count = 0
- args.each do |cask_token|
- begin
- cask = CaskLoader.load(cask_token)
-
- Installer.new(cask,
- binaries: binaries?,
- verbose: verbose?,
- force: force?,
- skip_cask_deps: skip_cask_deps?,
- require_sha: require_sha?).reinstall
-
- count += 1
- rescue CaskUnavailableError => e
- self.class.warn_unavailable_with_suggestion cask_token, e
- rescue CaskNoShasumError => e
- opoo e.message
- count += 1
- end
+ casks.each do |cask|
+ Installer.new(cask, binaries: binaries?,
+ verbose: verbose?,
+ force: force?,
+ skip_cask_deps: skip_cask_deps?,
+ require_sha: require_sha?).reinstall
end
-
- 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 b24091aef..9d1a16f15 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/search.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb
@@ -1,10 +1,6 @@
module Hbc
class CLI
class Search < AbstractCommand
- def initialize(*args)
- @args = args
- end
-
def run
results = self.class.search(*args)
self.class.render_results(*results)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index 97208232b..86fc98eaa 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -1,5 +1,3 @@
-require "English"
-
module Hbc
class CLI
class Style < AbstractCommand
@@ -33,7 +31,7 @@ module Hbc
elsif args.any? { |file| File.exist?(file) }
args
else
- args.map { |token| CaskLoader.path(token) }
+ casks.map(&:sourcefile_path)
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
index 33ee5afa9..c0697c808 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
@@ -9,9 +9,12 @@ module Hbc
end
def run
- args.each do |cask_token|
- odebug "Uninstalling Cask #{cask_token}"
- cask = CaskLoader.load(cask_token)
+ raise CaskError, "Uninstall incomplete." if uninstall_casks == :incomplete
+ end
+
+ def uninstall_casks
+ casks.each do |cask|
+ odebug "Uninstalling Cask #{cask}"
raise CaskNotInstalledError, cask unless cask.installed? || force?
@@ -27,8 +30,8 @@ module Hbc
single = versions.count == 1
puts <<-EOS.undent
- #{cask_token} #{versions.join(", ")} #{single ? "is" : "are"} still installed.
- Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask_token}`.
+ #{cask} #{versions.join(", ")} #{single ? "is" : "are"} still installed.
+ Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask}`.
EOS
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
index 3c07ff9e8..d12943106 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
@@ -7,9 +7,12 @@ module Hbc
end
def run
- args.each do |cask_token|
- odebug "Zapping Cask #{cask_token}"
- cask = CaskLoader.load(cask_token)
+ raise CaskError, "Zap incomplete." if zap_casks == :incomplete
+ end
+
+ def zap_casks
+ casks.each do |cask|
+ odebug "Zapping Cask #{cask}"
Installer.new(cask, verbose: verbose?).zap
end
end