aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-16 11:37:49 +0100
committerGitHub2017-03-16 11:37:49 +0100
commitc4d8b1696c90fa54f0e2f4bce3c734f7a657662b (patch)
tree58f3ad399870aca5329b7461d41cf8e12c885328 /Library/Homebrew/cask/lib
parent6c180e500827f9513304c96bcb43db31a31c5ae0 (diff)
parent7532545140c1ce0da370b2b3124e488dbb11fc41 (diff)
downloadbrew-c4d8b1696c90fa54f0e2f4bce3c734f7a657662b.tar.bz2
Merge pull request #2309 from axiac/cask-outdated
add command 'cask outdated'
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask.rb24
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/outdated.rb39
3 files changed, 64 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb
index 3f8da25b7..cf5f2b37a 100644
--- a/Library/Homebrew/cask/lib/hbc/cask.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask.rb
@@ -89,6 +89,30 @@ module Hbc
metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb")
end
+ def outdated?(greedy = false)
+ !outdated_versions(greedy).empty?
+ end
+
+ def outdated_versions(greedy = false)
+ # special case: tap version is not available
+ return [] if version.nil?
+
+ if greedy
+ return versions if version.latest?
+ elsif auto_updates
+ return []
+ end
+
+ installed = versions
+ current = installed.last
+
+ # not outdated unless there is a different version on tap
+ return [] if current == version
+
+ # collect all installed versions that are different than tap version and return them
+ installed.select { |v| v != version }
+ end
+
def to_s
@token
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index 27bea06ef..aa795fc59 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -15,6 +15,7 @@ require "hbc/cli/home"
require "hbc/cli/info"
require "hbc/cli/install"
require "hbc/cli/list"
+require "hbc/cli/outdated"
require "hbc/cli/reinstall"
require "hbc/cli/search"
require "hbc/cli/style"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
new file mode 100644
index 000000000..d608beab5
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
@@ -0,0 +1,39 @@
+module Hbc
+ class CLI
+ class Outdated < Base
+ def self.run(*args)
+ greedy = args.include?("--greedy")
+ verbose = ($stdout.tty? || CLI.verbose?) && !args.include?("--quiet")
+
+ cask_tokens = cask_tokens_from(args)
+ casks_to_check = if cask_tokens.empty?
+ Hbc.installed
+ else
+ cask_tokens.map { |token| Hbc.load(token) }
+ end
+
+ casks_to_check.each do |cask|
+ odebug "Checking update info of Cask #{cask}"
+ list_if_outdated(cask, greedy, verbose)
+ end
+ end
+
+ def self.list_if_outdated(cask, greedy, verbose)
+ return unless cask.outdated?(greedy)
+
+ if verbose
+ outdated_versions = cask.outdated_versions(greedy)
+ outdated_info = "#{cask.token} (#{outdated_versions.join(", ")})"
+ current_version = cask.version.to_s
+ puts "#{outdated_info} != #{current_version}"
+ else
+ puts cask.token
+ end
+ end
+
+ def self.help
+ "list the outdated installed Casks"
+ end
+ end
+ end
+end