lib/github_cli/editor.rb in github_cli-0.4.4 vs lib/github_cli/editor.rb in github_cli-0.5.0
- old
+ new
@@ -2,25 +2,30 @@
module GithubCLI
# This class determines editor to use to open the output.
class Editor
- def initialize(options={})
+ attr_accessor :filename
+
+ def initialize(filename, options={})
+ @filename = filename
end
def editor
- editors = [ ENV['GHC_EDITOR'], ENV['VISUAL'], ENV['EDITOR'], 'vi' ]
- editor = GithubCLI.config['editor']
- editor ||= editors.find { |e| !e.nil? && !e.empty? }
+ editors = [ ENV['GCLI_EDITOR'], ENV['VISUAL'], ENV['EDITOR'], 'vi' ]
+ editors.unshift(GithubCLI.config['core.editor'])
+ editors.compact.uniq.find { |editor| System.command? editor }
end
- def open(name)
+ def open(name=nil)
if editor
- command = "#{editor} #{name}"
+ 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
end # Editor
end # GithubCLI