Module: Norikra::Client::CLIUtil

Included in:
Admin, CLI, Event, Field, Query, Target
Defined in:
lib/norikra/client/cli.rb,
lib/norikra/client/cli/parser.rb,
lib/norikra/client/cli/formatter.rb

Defined Under Namespace

Modules: Formatter, Parser

Instance Method Summary collapse

Instance Method Details

#client(options) ⇒ Object



9
10
11
# File 'lib/norikra/client/cli.rb', line 9

def client(options)
  Norikra::Client.new(options[:host], options[:port])
end

#formatter(format, *args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/norikra/client/cli/formatter.rb', line 2

def formatter(format, *args)
  format ||= 'json'
  case format
  when /^json$/i
    require 'json'
    Formatter::JSON.new(*args)
  when /^ltsv$/i
    require 'ltsv'
    Formatter::LTSV.new(*args)
  else
    raise ArgumentError, "unknown format name: #{format}"
  end
end

#parser(format, *args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/norikra/client/cli/parser.rb', line 2

def parser(format, *args)
  format ||= 'json'
  case format
  when /^json$/i
    require 'json'
    Parser::JSON.new(*args)
  when /^ltsv$/i
    require 'ltsv'
    Parser::LTSV.new(*args)
  else
    raise ArgumentError, "unknown format name: #{format}"
  end
end

#wrapObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/norikra/client/cli.rb', line 12

def wrap
  begin
    yield
  rescue Norikra::RPC::ClientError => e
    puts "Failed: " + e.message
  rescue Norikra::RPC::ServerError => e
    puts "ERROR on norikra server: " + e.message
    puts " For more details, see norikra server's logs"
  end
end