Class: GithubCLI::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/github_cli/editor.rb

Overview

This class determines editor to use to open the output.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ Editor

Returns a new instance of Editor


11
12
13
# File 'lib/github_cli/editor.rb', line 11

def initialize(filename, options={})
  @filename = filename
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename


9
10
11
# File 'lib/github_cli/editor.rb', line 9

def filename
  @filename
end

Instance Method Details

#editorObject


15
16
17
18
19
# File 'lib/github_cli/editor.rb', line 15

def editor
  editors = [ ENV['GCLI_EDITOR'], ENV['VISUAL'], ENV['EDITOR'], 'vi' ]
  editors.unshift(GithubCLI.config['core.editor'])
  editors.compact.uniq.find { |editor| System.command? editor }
end

#open(name = nil) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/github_cli/editor.rb', line 21

def open(name=nil)
  if editor
    command = "#{editor} #{filename}"
    success = system(command)
    GithubCLI.ui.info "Could not run '#{command}'" unless success
    exit success
  else
    GithubCLI.info("To open output, set $EDITOR or $VISUL")
    exit 1
  end
end