Skip to content

Commit

Permalink
Merge pull request #2820 from rolandwalker/exit_code_on_list_fail
Browse files Browse the repository at this point in the history
exit with errorcode 1 when a list error occurs
  • Loading branch information
phinze committed Feb 8, 2014
2 parents bc3ed71 + 6529278 commit 081110d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 14 additions & 3 deletions lib/cask/cli/list.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
class Cask::CLI::List
def self.run(*arguments)
if arguments.any?
list_files(*arguments)
retval = list_files(*arguments)
else
list_installed
retval = list_installed
end
# retval is ternary: true/false/nil
if retval.nil?
raise CaskError.new("nothing to list")
elsif ! retval
raise CaskError.new("listing incomplete")
end
end

def self.list_files(*cask_names)
count = 0
cask_names.each do |cask_name|
odebug "Listing files for Cask #{cask_name}"
cask = Cask.load(cask_name)
if cask.installed?
count += 1
Cask::PrettyListing.new(cask).print
else
opoo "#{cask} is not installed"
end
end
count == 0 ? nil : count == cask_names.length
end

def self.list_installed
puts_columns Cask.installed.map(&:to_s)
columns = Cask.installed.map(&:to_s)
puts_columns columns
columns.empty? ? nil : Cask.installed.length == columns.length
end

def self.help
Expand Down
12 changes: 6 additions & 6 deletions test/cask/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it "creates the appdir if it does not exist" do
Cask.appdir.rmdir
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
Cask.appdir.directory?.must_equal true
end
Expand All @@ -34,7 +34,7 @@
begin
ENV['HOMEBREW_CASK_OPTS'] = "--appdir=#{custom_applications_dir}"
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
ensure
ENV.delete 'HOMEBREW_CASK_OPTS'
Expand All @@ -47,7 +47,7 @@
it "creates the qlplugindir if it does not exist" do
Cask.qlplugindir.rmdir
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
Cask.qlplugindir.directory?.must_equal true
end
Expand All @@ -64,7 +64,7 @@
begin
ENV['HOMEBREW_CASK_OPTS'] = "--qlplugindir=#{custom_qlplugin_dir}"
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
ensure
ENV.delete 'HOMEBREW_CASK_OPTS'
Expand All @@ -86,7 +86,7 @@
begin
ENV['HOMEBREW_CASK_OPTS'] = "--caskroom=#{custom_caskroom_dir}"
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
ensure
ENV.delete 'HOMEBREW_CASK_OPTS'
Expand All @@ -100,7 +100,7 @@
Cask::CLI.expects(:exit).with(1)
Cask::CLI.expects(:lookup_command).raises(CaskError)
shutup {
Cask::CLI.process('list')
Cask::CLI.process('doctor')
}
end
end
Expand Down

0 comments on commit 081110d

Please sign in to comment.