44 lines
967 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
class CLI
2017-05-20 19:08:03 +02:00
class Create < AbstractCommand
2017-05-21 00:15:56 +02:00
def initialize(*)
super
raise CaskUnspecifiedError if args.empty?
raise ArgumentError, "Only one Cask can be created at a time." if args.count > 1
end
2017-05-19 21:20:51 +02:00
def run
2017-05-21 00:15:56 +02:00
cask_token = args.first
cask_path = CaskLoader.path(cask_token)
2016-09-24 13:52:43 +02:00
raise CaskAlreadyCreatedError, cask_token if cask_path.exist?
2016-08-18 22:11:42 +03:00
2017-05-21 00:15:56 +02:00
odebug "Creating Cask #{cask_token}"
2016-09-24 13:52:43 +02:00
File.open(cask_path, "w") do |f|
2017-05-19 21:20:51 +02:00
f.write self.class.template(cask_token)
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
exec_editor cask_path
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.template(cask_token)
2017-10-15 02:28:32 +02:00
<<~EOS
2016-09-24 13:52:43 +02:00
cask '#{cask_token}' do
version ''
sha256 ''
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
url 'https://'
name ''
homepage ''
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
app ''
end
EOS
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
def self.help
"creates the given Cask and opens it in an editor"
end
end
2016-08-18 22:11:42 +03:00
end
end