bin/onering in onering-client-0.0.4 vs bin/onering in onering-client-0.0.6
- old
+ new
@@ -4,32 +4,62 @@
# list [options] field [key:value ..]
# search [options] [key:value .. ]
# provision [options] [key:value .. ] [pxe profile | ]
-require 'rubygems'
require 'json'
+require 'rubygems'
require 'subcommander'
require 'onering'
+require 'yaml'
-Onering::API::Device.connect
+include Subcommander
-action = ARGV.shift
-case (action && action.to_sym)
-when :ls, :list
- Onering::API::Device.list(ARGV.shift, (ARGV.empty? ? {} : {
- :filter => ARGV
- }))
-when :s, :search
- Onering::API::Device.find(ARGV)
+def print_format(data)
+ puts YAML.dump(data)
+end
-when :save
- data = (STDIN.tty? && ARGV.length > 1 ? File.read(File.expand_path(ARGV.last)) : STDIN.read)
+subcommander.version = Gem.loaded_specs['onering-client'].version.to_s
+subcommander.desc = Gem.loaded_specs['onering-client'].description
- if data
- data = JSON.load(data)
- Onering::API::Device.save(ARGV.first, data)
+#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
+
+# 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)
+ end
end
-else
- STDERR.puts "Usage: onering [subcommand] [options]"
+
+# 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.exec do
+ field = sc[:args].first
+ filter = sc[:filter]
+
+ print_format api.list(field, filter)
+ 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)
+ end
+ end
end
+
+
+subcommander.go!
\ No newline at end of file