File: cli.rb

package info (click to toggle)
ruby-neovim 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 548 kB
  • sloc: ruby: 4,178; sh: 23; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "neovim/connection"
require "neovim/event_loop"
require "neovim/host"
require "neovim/version"
require "optparse"

module Neovim
  class Host
    # @api private
    class CLI
      def self.run(path, argv, inn, out, err)
        cmd = File.basename(path)

        OptionParser.new do |opts|
          opts.on("-V", "--version") do
            out.puts Neovim::VERSION
            exit(0)
          end

          opts.on("-h", "--help") do
            out.puts "Usage: #{cmd} [-hV] rplugin_path ..."
            exit(0)
          end
        end.order!(argv)

        if inn.tty?
          err.puts("Can't run #{cmd} interactively.")
          exit(1)
        else
          conn = Connection.new(inn, out)
          event_loop = EventLoop.new(conn)

          Host.run(argv, event_loop)
        end
      rescue OptionParser::InvalidOption => e
        err.puts(e.message)
        exit(1)
      end
    end
  end
end