Sha256: 51404f377839c5c6294489345862ada69f3eb0ae6efc65d2228069e44d610c95

Contents?: true

Size: 786 Bytes

Versions: 13

Compression:

Stored size: 786 Bytes

Contents

# encoding: utf-8

module GithubCLI
  # This class determines editor to use to open the output.
  class Editor

    attr_accessor :filename

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

    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

    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

  end # Editor
end # GithubCLI

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
github_cli-0.6.2 lib/github_cli/editor.rb
github_cli-0.6.1 lib/github_cli/editor.rb
github_cli-0.6.0 lib/github_cli/editor.rb
github_cli-0.5.9 lib/github_cli/editor.rb
github_cli-0.5.8 lib/github_cli/editor.rb
github_cli-0.5.7 lib/github_cli/editor.rb
github_cli-0.5.6 lib/github_cli/editor.rb
github_cli-0.5.5 lib/github_cli/editor.rb
github_cli-0.5.4 lib/github_cli/editor.rb
github_cli-0.5.3 lib/github_cli/editor.rb
github_cli-0.5.2 lib/github_cli/editor.rb
github_cli-0.5.1 lib/github_cli/editor.rb
github_cli-0.5.0 lib/github_cli/editor.rb