bin/onering in onering-client-0.0.7 vs bin/onering in onering-client-0.0.8

- old
+ new

@@ -9,16 +9,31 @@ require 'json' require 'rubygems' require 'subcommander' require 'onering' require 'yaml' +require 'pp' include Subcommander -def print_format(data) - puts YAML.dump(data) +def print_format(data, format=:yaml) + case format + when :text + if data.is_a?(Hash) + pp data + elsif data.is_a?(Array) + puts data.join("\n") + else + puts data.to_s + end + when :yaml + puts YAML.dump(data) + + else + STDERR.puts "Invalid format: #{format}" + end end subcommander.version = Gem.loaded_specs['onering-client'].version.to_s subcommander.desc = Gem.loaded_specs['onering-client'].description @@ -31,35 +46,36 @@ # GET devices.subcommand :get, "Get a single node by ID" do |sc| sc.usage = "onering devices get ID" sc.exec do - print_format api.get(sc[:args].first) + print_format(api.get(sc[:args].first)) end end # LIST devices.subcommand :list, "List field values" do |sc| sc.usage = "onering devices list [-f FILTER] FIELD" sc.opt :filter, '-f', '--filter FILTER', "A urlquery filter string" + sc.ops :as_txt, '-t', '--as-text', "Return the results as text" sc.exec do field = sc[:args].first filter = sc[:filter] - print_format api.list(field, { + print_format(api.list(field, { :filter => filter - }) + }), (sc[:as_txt] ? :text : nil)) end end # FIND devices.subcommand :find, "Finds all nodes that match a urlquery filter string" do |sc| sc.arity = 1 sc.usage = "onering devices find FILTER" sc.exec do - print_format api.find(sc[:args].first) + print_format(api.find(sc[:args].first)) end end end \ No newline at end of file