2019-04-19 15:38:03 +09:00
|
|
|
# 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 Edit < AbstractCommand
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.min_named
|
|
|
|
:cask
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.max_named
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.description
|
|
|
|
"Open the given <cask> for editing."
|
|
|
|
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 edited at a time."
|
2017-05-21 00:15:56 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 22:01:50 +02:00
|
|
|
def run
|
2016-09-24 13:52:43 +02:00
|
|
|
exec_editor cask_path
|
2017-09-11 08:37:15 +02:00
|
|
|
rescue CaskUnavailableError => e
|
2019-04-20 14:07:29 +09:00
|
|
|
reason = e.reason.empty? ? +"" : +"#{e.reason} "
|
2017-09-11 08:37:15 +02:00
|
|
|
reason.concat("Run #{Formatter.identifier("brew cask create #{e.token}")} to create a new Cask.")
|
2019-04-20 14:07:29 +09:00
|
|
|
raise e.class.new(e.token, reason.freeze)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-15 22:04:20 +02:00
|
|
|
def cask_path
|
|
|
|
casks.first.sourcefile_path
|
2019-04-20 23:56:55 +02:00
|
|
|
rescue CaskInvalidError, CaskUnreadableError, MethodDeprecatedError
|
2017-10-15 22:04:20 +02:00
|
|
|
path = CaskLoader.path(args.first)
|
|
|
|
return path if path.file?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-10-15 22:04:20 +02:00
|
|
|
raise
|
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|