#!/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 = < opts[:project]) result = nil unless opts[:tags] or opts[:tags_for] or opts[:tagged?] or opts[:hosts_tagged_with] if args.first opts[:tagged?] = args.first else puts parser puts "\nERROR: insufficient arguments" exit 1 end end result = \ if opts[:tags] interpreter.tags elsif opts[:tags_for] interpreter.tags_for(opts[:tags_for]) elsif opts[:tagged?] exit(interpreter.tagged?(opts[:tagged?]) ? 0 : 1) elsif opts[:hosts_tagged_with] interpreter.hosts_tagged_with(opts[:hosts_tagged_with]) end puts( if result.nil? result.inspect elsif opts[:yaml] result.to_yaml elsif opts[:xml] require 'active_support/core_ext/hash' require 'active_support/core_ext/array' result.to_xml else case result when String: result when Set: result.sort.to_a.join(' ') when Array: result.sort.join(' ') else result.inspect end end ) exit 0 end