#!/usr/bin/env ruby $LOAD_PATH << File.expand_path("../../lib", __FILE__) require 'hieracles' opt = Hieracles::Optparse.new(ARGV) if opt.options.has_key? :version puts Hieracles.version exit(0) end fqdn = opt.payload[0] command = opt.payload[1] args = opt.payload[2..-1] unless fqdn && command puts Hieracles::Help.usage exit(1) end if Hieracles::Format.method_defined? command node = Hieracles::Node.new fqdn, opt.options begin formatter = Object.const_get("Hieracles::Formats::#{Hieracles::Config.format}") rescue puts " Unknown format #{Hieracles::Config.format}" exit(1) end dispatch = formatter.new node puts dispatch.send(command.to_sym, args) else puts " Unknown command: #{command}" Hieracles::Help.usage exit(1) end