Sha256: e52c46eec752efb457ebbb07167c799a9725fc5b476f207814f30d47f670d310

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

#!/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[1]
  puts Hieracles::Options::Ppdb.usage
  exit(1)
end

command = "#{opt.payload[0]}_#{opt.payload[1]}"
args = opt.payload[2..-1] || []

Hieracles::Config.load opt.options

if Hieracles::Puppetdb::Request.method_defined? command
  request = Hieracles::Puppetdb::Request.new Hieracles::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
    format = Hieracles::Formats::Console.new(nil)
    resp = meth.call(*args)
    puts format.build_list(resp.data, resp.notifications, [])
  end
else
  puts "*** Unknown command: #{command}"
  puts Hieracles::Options::Ppdb.usage
  exit(1)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hieracles-0.2.2 bin/ppdb
hieracles-0.2.1 bin/ppdb