Sha256: 1c3169103848d57c77aed60f1e8107c61e3f468ba3650f95ecbd978365d87d86

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 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[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 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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hieracles-0.4.2 bin/ppdb
hieracles-0.4.1 bin/ppdb
hieracles-0.4.0 bin/ppdb
hieracles-0.3.6 bin/ppdb
hieracles-0.3.5 bin/ppdb
hieracles-0.3.4 bin/ppdb
hieracles-0.3.3 bin/ppdb
hieracles-0.3.2 bin/ppdb