bin/onering in onering-client-0.0.16 vs bin/onering in onering-client-0.0.17

- old
+ new

@@ -33,15 +33,16 @@ end subcommander.version = ::Gem.loaded_specs['onering-client'].version.to_s subcommander.desc = ::Gem.loaded_specs['onering-client'].description -#subcommander.opt :server, '-s', '--server', 'Specify the Onering server URL' - subcommand :devices, "Operations related to Onering's assets database" do |devices| api = Onering::API::Devices - api.connect ENV['ONERING_URL'] + api.connect({ + :host => ENV['ONERING_URL'], + :pemfile => ENV['ONERING_PEM'] + }) def _field(action, field, value, opts={}) rv = [] ids = [] @@ -135,10 +136,63 @@ sc.exec do unless STDIN.tty? begin json = ::JSON.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}" + exit 1 + end + end + end + end +end + + +subcommand :users, "Manage Onering users" do |users| + api = Onering::API::Auth + api.connect({ + :host => ENV['ONERING_URL'], + :pemfile => ENV['ONERING_PEM'] + }) + +# SHOW + users.subcommand :show, "Print out a single user by ID" do |sc| + sc.usage = "onering users show ID" + + sc.exec do + id = sc[:args].first + print_format(api.get(:users, id)) + end + end + +# LIST + users.subcommand :list, "List users" do |sc| + sc.usage = "onering users list FIELD" + sc.opt :as_txt, '-t', '--as-text', "Return the results as text" + + sc.exec do + field = sc[:args].first + filter = sc[:filter] + + print_format(api.list(:users, field, { + :filter => filter + }), (sc[:as_txt] ? :text : nil)) + end + end + +# SAVE + users.subcommand :save, "Creates or updates a new device in Onering, reading a JSON document from standard input" do |sc| + sc.usage = "cat user.json | onering users save [ID]" + + sc.exec do + unless STDIN.tty? + begin + json = ::JSON.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}" exit 1 end \ No newline at end of file