Sha256: d256e8d504d4e306faac36069af1b2ac16ee385b0dbe5f62574951a8ada88de8

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

#!/usr/bin/env ruby

# XXX What can go wrong with this loading approach?
libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb"))
  $LOAD_PATH.unshift(libdir)
end

require 'rubygems'
require 'optparse'
require 'automateit'

OptionParser.new do |parser|
  PROG = File.basename($0)
  opts = {}
  parser.banner = <<EOB
#{PROG} - tool for querying AutomateIt fields

Usage: #{PROG} [options] query

Examples:
  # Load 'myproject' and get value of 'user' field in 'myapp' hash:
  #{PROG} -p myproject myapp#user

  # Same but using environmental variable to specify project:
  AUTOMATEIT_PROJECT=myproject
  #{PROG} myapp#user

  # Dump the 'myapp' hash contents as YAML
  #{PROG} -y myapp#user

Options:
EOB
  parser.on("-p", "--project PATH", "Set project path") do |v|
    opts[:project] = v
  end

  parser.on("-Y", "--yaml", "Dump as YAML") do |v|
    opts[:yaml] = v
  end

  parser.on("-a", "--add TAGS", "Add list of space separated tags") do |v|
    opts[:tags] = [v.split].flatten
  end

  parser.on("-v", "--version", "Display version") do |v|
    puts AutomateIt::VERSION
    exit 0
  end

  parser.on("-h", "--help", "Display this help message") do |v|
    puts parser
    exit
  end

  args = parser.parse!.dup

  # Clear ARGV so that IRB doesn't try to parse our options
  opts[:args] = args
  ARGV.clear

  query = args.first unless args.empty?

  interpreter = AutomateIt.new(:project => opts[:project])
  result = interpreter.lookup(query)
  if result.nil?
    puts result.inspect
    exit 1
  elsif opts[:yaml]
    puts result.to_yaml
  else
    puts result.is_a?(String) ? result : result.inspect
  end
  exit 0
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
automate-it-0.9.2 bin/aifield
automate-it-0.9.1 bin/aifield
automate-it-0.9.0 bin/aifield
automateit-0.80116 bin/aifield
automateit-0.71230 bin/aifield
automateit-0.80624 bin/aifield