class Sumo::CLI

This class is used to define a CLI.

Public Instance Methods

execute() click to toggle source

This method is called when the CLI is run.

# File lib/sumo/cli.rb, line 25
def execute
  if version?
    $stdout.puts Sumo::VERSION
  elsif records?
    search.records.each { |record| $stdout.puts record }
  else
    search.messages.each { |msg| $stdout.puts format_message(msg['_raw']) }
  end
rescue StandardError => ex
  $stderr.puts "#{ex.class}: #{ex.message}"
  exit 1
end

Private Instance Methods

format_message(raw) click to toggle source
# File lib/sumo/cli.rb, line 38
def format_message(raw)
  JSON.parse(raw)[extract_key] || raw
rescue StandardError
  raw
end