Browse Source

create casks with `brew cask edit foo --create`

phinze 12 years ago
parent
commit
bf33643526
  1. 22
      lib/cask/cli.rb
  2. 6
      lib/cask/cli/edit.rb
  3. 13
      test/cli/edit_test.rb
  4. 19
      test/cli/options_test.rb

22
lib/cask/cli.rb

@ -39,16 +39,28 @@ class Cask::CLI
list.sort
end
def self.process_options(args)
allrgs = Shellwords.shellsplit(ENV['HOMEBREW_CASK_OPTS'] || "") + args
OptionParser.new do |opts|
def self.parser
@parser ||= OptionParser.new do |opts|
opts.on("--appdir=MANDATORY") do |v|
Cask.appdir = Pathname.new File.expand_path(v)
end
end.parse!(allrgs)
return allrgs
end
end
def self.process_options(args)
all_args = Shellwords.shellsplit(ENV['HOMEBREW_CASK_OPTS'] || "") + args
remaining = []
while !all_args.empty?
begin
head = all_args.shift
remaining.concat(parser.parse([head]))
rescue OptionParser::InvalidOption
remaining << head
retry
end
end
remaining
end
class NullCommand
def initialize(attempted_name)

6
lib/cask/cli/edit.rb

@ -1,8 +1,10 @@
module Cask::CLI::Edit
def self.run(*arguments)
cask_name, *_ = *arguments
cask_name, *args = *arguments
cask_path = Cask.path(cask_name)
raise CaskUnavailableError, cask_name + ".rb" if cask_path.nil? || !cask_path.file?
unless cask_path.exist? || args.include?('--create')
raise CaskUnavailableError, "#{cask_name}, add --create to make a new cask with this name"
end
exec_editor cask_path
end

13
test/cli/edit_test.rb

@ -36,4 +36,17 @@ describe Cask::CLI::Edit do
[Cask.path('adium')]
]
end
it 'raises an exception when the cask doesnt exist' do
lambda {
Cask::CLI::Edit.run('notacask')
}.must_raise CaskUnavailableError
end
it 'allows new casks to be created with the --create flag' do
Cask::CLI::Edit.run('brand-spankin-new', '--create')
Cask::CLI::Edit.editor_commands.must_equal [
[Cask.tapspath.join(Cask.default_tap, 'Casks', 'brand-spankin-new.rb')]
]
end
end

19
test/cli/options_test.rb

@ -2,21 +2,24 @@ require 'test_helper'
describe Cask::CLI do
it "supports setting the appdir" do
shutup do
Cask::CLI.process %w{help --appdir=/some/path}
end
Cask::CLI.process_options %w{help --appdir=/some/path/foo}
Cask.appdir.must_equal Pathname.new File.expand_path "/some/path"
Cask.appdir.must_equal Pathname('/some/path/foo')
end
it "supports setting the appdir from ENV" do
ENV['HOMEBREW_CASK_OPTS'] = "--appdir=/some/path"
ENV['HOMEBREW_CASK_OPTS'] = "--appdir=/some/path/bar"
Cask::CLI.process_options %w{help}
shutup do
Cask::CLI.process %w{help}
Cask.appdir.must_equal Pathname('/some/path/bar')
end
Cask.appdir.must_equal Pathname.new File.expand_path "/some/path"
it "allows additional options to be passed through" do
rest = Cask::CLI.process_options %w{edit foo --create --appdir=/some/path/qux}
Cask.appdir.must_equal Pathname('/some/path/qux')
rest.must_equal %w{edit foo --create}
end
after do

Loading…
Cancel
Save