Class: Hbc::CLI::Edit

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli/edit.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, needs_init?, run, visible

Methods included from Options

included, #process_arguments

Constructor Details

#initializeEdit

Returns a new instance of Edit



4
5
6
7
8
# File 'Library/Homebrew/cask/lib/hbc/cli/edit.rb', line 4

def initialize(*)
  super
  raise CaskUnspecifiedError if args.empty?
  raise ArgumentError, "Only one Cask can be edited at a time." if args.count > 1
end

Class Method Details

.helpObject



26
27
28
# File 'Library/Homebrew/cask/lib/hbc/cli/edit.rb', line 26

def self.help
  "edits the given Cask"
end

Instance Method Details

#cask_pathObject



18
19
20
21
22
23
24
# File 'Library/Homebrew/cask/lib/hbc/cli/edit.rb', line 18

def cask_path
  casks.first.sourcefile_path
rescue CaskInvalidError
  path = CaskLoader.path(args.first)
  return path if path.file?
  raise
end

#runObject



10
11
12
13
14
15
16
# File 'Library/Homebrew/cask/lib/hbc/cli/edit.rb', line 10

def run
  exec_editor cask_path
rescue CaskUnavailableError => e
  reason = e.reason.empty? ? "" : "#{e.reason} "
  reason.concat("Run #{Formatter.identifier("brew cask create #{e.token}")} to create a new Cask.")
  raise e.class.new(e.token, reason)
end