#!/usr/bin/env ruby $LOAD_PATH << File.expand_path("../../lib", __FILE__) require 'hieracles' require 'hieracles/options/ppdb' opt = Hieracles::Options::Ppdb.new(ARGV) if opt.options.has_key? :version puts Hieracles.version exit(0) end unless opt.payload[0] puts Hieracles::Options::Ppdb.usage exit(1) end endpoint = opt.payload[0] if Hieracles::Puppetdb::Request.method_defined? endpoint command = endpoint args = opt.payload[1..-1] || [] elsif Hieracles::Puppetdb::Request.method_defined? "#{opt.payload[0]}_#{opt.payload[1]}" command = "#{opt.payload[0]}_#{opt.payload[1]}" args = opt.payload[2..-1] || [] else puts "*** Unknown command: #{command}" puts Hieracles::Options::Ppdb.usage exit(1) end config = Hieracles::Config.new opt.options request = Hieracles::Puppetdb::Request.new config.puppetdb meth = request.method(command.to_sym) required = request.method(command.to_sym).parameters.select { |arg| arg[0] == :req }.map { |arg| arg[1] } if args.length < required.length args = required.join(', ') puts "*** The #{command} method requires arguments: #{args}" exit(1) else if Hieracles::Config.format == 'Json' format = Hieracles::Formats::Json.new(nil) else format = Hieracles::Formats::Console.new(nil) end resp = meth.call(*args) puts format.build_list(resp.data, resp.notifications, []) end