bin/onering in onering-client-0.0.37 vs bin/onering in onering-client-0.0.39
- old
+ new
@@ -4,11 +4,11 @@
# list [options] field [key:value ..]
# search [options] [key:value .. ]
# provision [options] [key:value .. ] [pxe profile | ]
-require 'json'
+require 'multi_json'
require 'rubygems'
require 'subcommander'
require 'onering'
require 'pp'
@@ -32,11 +32,11 @@
require 'yaml'
puts YAML.dump(data)
when :json
require 'json'
- puts JSON.dump(data)
+ puts MultiJson.dump(data)
else
raise "Unknown output format #{format}"
end
end
@@ -77,14 +77,15 @@
end
# SHOW
devices.subcommand :show, "Print out a single node by ID" do |sc|
sc.usage = "onering devices show ID"
+ sc.opt :format, '-t', '--format FORMAT', "Return the results as FORMAT"
sc.exec do
id = sc[:args].first
- print_format(api.get(id))
+ print_format(api.get(id), sc[:format])
end
end
# GET [FIELD]
devices.subcommand :get, "Get a named field from one or more devices" do |sc|
@@ -145,11 +146,11 @@
sc.usage = "onering report | onering devices save [ID]"
sc.exec do
unless STDIN.tty?
begin
- json = ::JSON.load(STDIN.read)
+ json = ::MultiJson.load(STDIN.read)
raise "Input document must specify an ID" if sc[:args].empty? and not json['id']
rv = api.save((sc[:args].first || json['id']), json)
print_format(rv, :json) if rv
rescue Exception => e
@@ -199,11 +200,11 @@
sc.usage = "cat user.json | onering users save [ID]"
sc.exec do
unless STDIN.tty?
begin
- json = ::JSON.load(STDIN.read)
+ json = ::MultiJson.load(STDIN.read)
raise "Input document must specify an ID" if sc[:args].empty? and not json['id']
print_format(api.save((sc[:args].first || json['id']), json))
rescue Exception => e
STDERR.puts "#{e.class.name}: #{e.message}"
@@ -227,10 +228,10 @@
call.opt :opts, '-o', '--option KEY:VALUE', Array, "A comma-separated list of key:value querystrings to pass with the request"
call.exec do
rv = api.request(call[:args].first.to_sym, {
:method => (call[:method] || :get),
- :data => (STDIN.tty? ? {} : ::JSON.load(STDIN.read)),
+ :data => (STDIN.tty? ? {} : ::MultiJson.load(STDIN.read)),
:fields => (Hash[call[:opts].collect{|i| i.split(':',2) }] rescue {})
})
print_format(rv, call[:format] || :json) unless rv.nil? or rv.to_s.strip.chomp.empty?
end
\ No newline at end of file