Class: GithubCLI::Editor
- Inherits:
-
Object
- Object
- GithubCLI::Editor
- Defined in:
- lib/github_cli/editor.rb
Overview
This class determines editor to use to open the output.
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #editor ⇒ Object
-
#initialize(filename, options = {}) ⇒ Editor
constructor
A new instance of Editor.
- #open(name = nil) ⇒ Object
Constructor Details
#initialize(filename, options = {}) ⇒ Editor
Returns a new instance of Editor.
9 10 11 |
# File 'lib/github_cli/editor.rb', line 9 def initialize(filename, ={}) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
7 8 9 |
# File 'lib/github_cli/editor.rb', line 7 def filename @filename end |
Instance Method Details
#editor ⇒ Object
13 14 15 16 17 |
# File 'lib/github_cli/editor.rb', line 13 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
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/github_cli/editor.rb', line 19 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 |