From f866a18725c49953f0bce7927beb6c4d8784bfcd Mon Sep 17 00:00:00 2001 From: phinze Date: Sun, 17 Feb 2013 14:07:59 -0600 Subject: [PATCH] add `brew cask open` command thanks to @passcod for original implementation on his fork refs #72 --- lib/cask/cli/open.rb | 16 ++++++++++++++++ test/cli/open_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 lib/cask/cli/open.rb create mode 100644 test/cli/open_test.rb diff --git a/lib/cask/cli/open.rb b/lib/cask/cli/open.rb new file mode 100644 index 000000000..13300ab2d --- /dev/null +++ b/lib/cask/cli/open.rb @@ -0,0 +1,16 @@ +module Cask::CLI::Open + def self.run(*cask_names) + cask_names.each do |cask_name| + begin + cask = Cask.load(cask_name) + system "open", cask.homepage + rescue CaskUnavailableError => e + onoe e + end + end + end + + def self.help + "opens the homepage of the cask of the given name" + end +end diff --git a/test/cli/open_test.rb b/test/cli/open_test.rb new file mode 100644 index 000000000..1f90c9d81 --- /dev/null +++ b/test/cli/open_test.rb @@ -0,0 +1,41 @@ +require 'test_helper' + +module RecordSystemCalls + def system(*command) + system_commands << command + end + + def reset! + @system_commands = [] + end + + def system_commands + @system_commands ||= [] + end +end + +module Cask::CLI::Open + extend RecordSystemCalls +end + +describe Cask::CLI::Open do + before do + Cask::CLI::Open.reset! + end + + it 'opens the homepage for the specified cask' do + Cask::CLI::Open.run('alfred') + Cask::CLI::Open.system_commands.must_equal [ + ['open', 'http://www.alfredapp.com/'] + ] + end + + it 'works for multiple casks' do + Cask::CLI::Open.run('alfred', 'adium') + Cask::CLI::Open.system_commands.must_equal [ + ['open', 'http://www.alfredapp.com/'], + ['open', 'http://www.adium.im/'] + ] + end +end +