diff options
| author | Markus Reiter | 2017-05-20 03:30:46 +0200 |
|---|---|---|
| committer | Markus Reiter | 2017-05-22 02:51:16 +0200 |
| commit | 24f38a2e8ad3d6d7f39030ee901dcc496a684a5e (patch) | |
| tree | 2b33706b45bdf693dff9a693454131342b3ad281 /Library | |
| parent | ccafa1b75984f32e3e1fe5f860b561ada8876f96 (diff) | |
| download | brew-24f38a2e8ad3d6d7f39030ee901dcc496a684a5e.tar.bz2 | |
Refactor `CLI::List`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/list.rb | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index d9bf2187b..f79dc9a54 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -1,19 +1,24 @@ 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") + def self.run(*args) + new(*args).run + end - if arguments.delete("-l") - @options[:one] = true - opoo "Option -l is obsolete! Implying option -1." - end + def initialize(*args) + @cask_tokens = self.class.cask_tokens_from(args) + @one = true if args.delete("-1") + @versions = true if args.delete("--versions") + + return unless args.delete("-l") + @one = true + opoo "Option -l is obsolete! Implying option -1." + end - retval = arguments.any? ? list(*arguments) : list_installed + def run + retval = @cask_tokens.any? ? list : list_installed # retval is ternary: true/false/nil - if retval.nil? && !arguments.any? + if retval.nil? && !@cask_tokens.any? opoo "nothing to list" # special case: avoid exit code elsif retval.nil? raise CaskError, "nothing to list" @@ -22,22 +27,22 @@ module Hbc end end - def self.list(*cask_tokens) + def list count = 0 - cask_tokens.each do |cask_token| + @cask_tokens.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 +54,7 @@ module Hbc end end - count.zero? ? nil : count == cask_tokens.length + count.zero? ? nil : count == @cask_tokens.length end def self.list_artifacts(cask) @@ -59,13 +64,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 |
