bin/onering in onering-client-0.0.17 vs bin/onering in onering-client-0.0.18
- old
+ new
@@ -30,13 +30,18 @@
else
puts YAML.dump(data)
end
end
+def global_options(sc)
+ sc.send(:opt, :verbose, '-v', '--verbose', "Print out what the command is doing")
+end
+
subcommander.version = ::Gem.loaded_specs['onering-client'].version.to_s
subcommander.desc = ::Gem.loaded_specs['onering-client'].description
+
subcommand :devices, "Operations related to Onering's assets database" do |devices|
api = Onering::API::Devices
api.connect({
:host => ENV['ONERING_URL'],
:pemfile => ENV['ONERING_PEM']
@@ -200,7 +205,30 @@
end
end
end
end
+subcommand :call, "Call generic Onering API endpoints" do |call|
+ api = Onering::API::Base
+ api.connect({
+ :host => ENV['ONERING_URL'],
+ :pemfile => ENV['ONERING_PEM']
+ })
+
+ call.usage = "onering call path/to/endpoint"
+ call.arity = 1
+ call.opt :as_txt, '-t', '--as-text', "Return the results as text"
+ call.opt :method, '-m', '--method', "The HTTP method to use for the call (default: GET)"
+ 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? ? nil : ::JSON.load(STDIN.read)),
+ :fields => (Hash[call[:opts].collect{|i| i.split(':',2) }] rescue {})
+ })
+
+ print_format(rv, (call[:as_txt] ? :text : nil)) unless rv.nil? or rv.to_s.strip.chomp.empty?
+ end
+end
subcommander.go!
\ No newline at end of file