bin/onering in onering-client-0.0.83 vs bin/onering in onering-client-0.0.84
- old
+ new
@@ -6,11 +6,11 @@
require 'pp'
plugins = Onering::CLI.submodules.collect{|i| i.name.split('::').last.downcase }
global = Trollop::options do
banner <<-EOS
-onering command line client utility - version #{Onering::CLI::VERSION}
+onering command line client utility - version #{Onering::Client::VERSION}
Usage:
onering [global] [plugin] [subcommand] [options]
where [global] options are:
@@ -22,28 +22,43 @@
opt :param, "Additional query string parameters to include with the request in the format FIELD=VALUE. Can be specified multiple times.", :short => '-p', :type => :string, :multi => true
opt :format, "The output format for return values (i.e.: json, yaml, text)", :default => 'text', :short => '-t', :type => :string
opt :sslkey, "Location of the SSL client key to use for authentication", :short => '-c', :type => :string
opt :apikey, "The API token to use for authentication", :short => '-k', :type => :string
opt :quiet, "Suppress standard output", :short => '-q'
+ opt :verbosity, "Set the log level (fatal, error, warn, info, debug)", :short => '-v', :type => :string, :default => 'warn'
stop_on plugins
end
plugin = ARGV.shift
Trollop::die("plugin argument is requried") if plugin.nil?
+Onering::Logger.setup({
+ :destination => 'stderr',
+ :threshold => global[:verbosity]
+})
+
Onering::Config.load()
+
if plugins.include?(plugin)
begin
plugin = Onering::CLI.const_get(plugin.capitalize)
plugin.configure(global)
+
+ Onering::Logger.debug("Executing plugin #{plugin}\#run()", $0)
rv = plugin.run(ARGV)
+ Onering::Logger.debug("Outputting data as #{global[:format]}:", $0)
Onering::CLI.output(rv, global[:format])
+
rescue Onering::API::Errors::Exception => e
- STDERR.puts("[#{e.class.name.split('::').last}]".foreground(:red) + " #{e.message}")
+ Onering::Logger.fatal(e.message, e.class.name.split('::').last) rescue nil
exit 1
+
+ rescue Onering::Client::FatalError => e
+ exit 255
+
end
else
Trollop::die("unknown plugin #{plugin}")
end