55 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-09-06 08:29:14 +02:00
module Cask
2018-09-04 08:45:48 +01:00
class Cmd
2017-05-20 19:08:03 +02:00
class Create < AbstractCommand
2020-08-01 02:30:46 +02:00
def self.min_named
:cask
end
def self.max_named
1
end
def self.description
"Creates the given <cask> and opens it in an editor."
end
2017-05-21 00:15:56 +02:00
def initialize(*)
super
2020-08-01 02:30:46 +02:00
rescue Homebrew::CLI::MaxNamedArgumentsError
raise UsageError, "Only one cask can be created at a time."
2017-05-21 00:15:56 +02:00
end
2017-05-19 21:20:51 +02:00
def run
2020-08-01 02:30:46 +02:00
cask_token = args.named.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)
2018-07-11 15:17:40 +02:00
<<~RUBY
cask "#{cask_token}" do
version ""
sha256 ""
2016-08-18 22:11:42 +03:00
2019-04-06 09:30:59 +01:00
url "https://"
name ""
2020-07-29 15:40:31 +01:00
desc ""
homepage ""
2016-08-18 22:11:42 +03:00
app ""
2016-09-24 13:52:43 +02:00
end
2018-07-11 15:17:40 +02:00
RUBY
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
end