Class: Cask::Cmd::Edit

Inherits:
AbstractCommand show all
Defined in:
brew/Library/Homebrew/cask/cmd/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, run, visible

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Methods included from Options

#process_arguments

Constructor Details

#initializeEdit

Returns a new instance of Edit



6
7
8
9
10
# File 'brew/Library/Homebrew/cask/cmd/edit.rb', line 6

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



29
30
31
# File 'brew/Library/Homebrew/cask/cmd/edit.rb', line 29

def self.help
  "edits the given Cask"
end

Instance Method Details

#cask_pathObject



20
21
22
23
24
25
26
27
# File 'brew/Library/Homebrew/cask/cmd/edit.rb', line 20

def cask_path
  casks.first.sourcefile_path
rescue CaskInvalidError, CaskUnreadableError, MethodDeprecatedError
  path = CaskLoader.path(args.first)
  return path if path.file?

  raise
end

#runObject



12
13
14
15
16
17
18
# File 'brew/Library/Homebrew/cask/cmd/edit.rb', line 12

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.freeze)
end