Sha256: 7bcddda3670efc490eec247b7e8e086613e89ce79700545dae6174b810f01b1a

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/ruby

require 'sumo'
require 'sumo/version'
require 'time'
require 'optparse'

include Sumo

options = {
  :query_options => {},
  :config_file => DEFAULT_CONFIG_FILE,
  :key => nil
}

OptionParser.new do |opts|
  opts.banner = 'Usage: sumo [flags/options]'

  opts.separator ''
  opts.separator 'Specific options:'

  opts.on('-q', '--query QUERY', 'Search for QUERY (required)') do |q|
    options[:query] = q
  end

  opts.on('-f', '--from START', 'Begin at the given ISO8601 time') do |f|
    options[:query_options]['from'] = f
  end

  opts.on('-t', '--to END', 'Finish at the given ISO8601 time') do |t|
    options[:query_options]['to'] = t
  end

  opts.on('-z', '--time-zone ZONE', 'Use the given time zone') do |tz|
    options[:query_options]['tz'] = tz
  end

  opts.on('-c', '--config-file FILE',
          "Use the given config file instead of #{DEFAULT_CONFIG_FILE}") do |f|
    options[:config_file] = config_file
  end

  opts.on('-e', '--extract-key KEY', 'Extract the specified key') do |k|
    options[:key] = k
  end

  opts.on('-h', '--help', 'Print this message') do
    puts opts
    exit 0
  end

  opts.on('-v', '--version', 'Print the version') do
    puts VERSION
    exit 0
  end
end.parse!

if options[:query].nil?
  puts 'Please specify a query'
  exit 1
else
  begin
    puts search(options[:query],
                options: options[:query_options],
                key: options[:key],
                config_file: options[:config_file])
    exit 0
  rescue StandardError => ex
    puts ex.message
    exit 1
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sumo-search-0.1.1 bin/sumo