module Norikra::Client::CLIUtil

Public Instance Methods

client(options) click to toggle source
# File lib/norikra/client/cli.rb, line 9
def client(options)
  Norikra::Client.new(options[:host], options[:port])
end
formatter(format, *args) click to toggle source
# 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) click to toggle source
# 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
wrap() { || ... } click to toggle source
# 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