Class: ViewServer::ShowRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/view_server/show_runner.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



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
# File 'lib/view_server/show_runner.rb', line 5

def self.parse(args)
  options = {:port => 10021}
  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: show [options] [file]"

    opts.on("-e", "--extension EXTENSION", "File extension") do |v|
      options[:ext] = v
    end

    opts.on("-p", "--port PORT", "Port number. Default is 10021") do |v|
      options[:port] = Integer(v)
    end
  end

  opt_parser.parse!(args)

  filename = ARGV.first
  if filename
    data = File.read filename
    ext = File.extname(filename)[1..-1]
  else
    data = $stdin.read
    ext = options.fetch(:ext) {'txt'}
  end

  options.merge({:data => data, :ext => ext })
end

.run(args, launcher = Launcher.new) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/view_server/show_runner.rb', line 33

def self.run(args, launcher = Launcher.new)
  opts = parse(args)

  if opts[:port] == -1
    ViewServer::Server.new(launcher).show(opts[:data], opts[:ext])
  else
    ViewServer::Client.new(opts[:port]).show(opts[:data], opts[:ext])
  end
end