lib/onering/cli/assets.rb in onering-client-0.4.2 vs lib/onering/cli/assets.rb in onering-client-0.4.3

- old
+ new

@@ -10,15 +10,17 @@ Usage: onering [global] assets [options] [subcommands] Subcommands: - find <urlquery> - get <property> [property2 ..] - list <property> [property2 ..] + find <urlquery> + get <property> [property2 ..] + list <property> [property2 ..] save - set <property> <value> + set <property> <value> + tag <tag1>[ tag2 .. tagN] + untag <tag1>[ tag2 .. tagN] Options: EOS opt :query, "The Onering urlquery to filter devices by", :short => '-f', :type => :string @@ -37,11 +39,11 @@ when :show return @api.assets.show(args[0]) # ----------------------------------------------------------------------------- when :get - Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Devices") unless args.length == 1 + Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Assets") unless args.length == 1 if @opts[:query_given] # doing this until a bulk field query endpoint is built return @api.list('id', { :filter => @opts[:query] @@ -52,11 +54,11 @@ end # ----------------------------------------------------------------------------- when :set - Onering::Logger.fatal!("Expected 2 parameters, got #{args.length}", "Onering::CLI::Devices") unless args.length == 2 + Onering::Logger.fatal!("Expected 2 parameters, got #{args.length}", "Onering::CLI::Assets") unless args.length == 2 if @opts[:query] # doing this until a bulk field set endpoint is built return @api.list('id', { :filter => @opts[:query] @@ -67,18 +69,18 @@ end # ----------------------------------------------------------------------------- when :list - Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Devices") unless args.length >= 1 + Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Assets") unless args.length >= 1 return @api.list(args, { :filter => @opts[:query] }.compact) # ----------------------------------------------------------------------------- when :find - Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Devices") unless args.length == 1 + Onering::Logger.fatal!("Expected 1 parameter, got #{args.length}", "Onering::CLI::Assets") unless args.length == 1 return @api.find(args[0]) # ----------------------------------------------------------------------------- when :save rv = @api.save(args[0] || @opts[:id]) do @@ -89,16 +91,47 @@ # read from specified file elsif (File.readable?(args[1]) rescue false) File.read(args[1]) else - Onering::Logger.fatal!("Cannot save data, no input data specified", "Onering::CLI::Devices") + Onering::Logger.fatal!("Cannot save data, no input data specified", "Onering::CLI::Assets") end end rv.parsed_response + +# ----------------------------------------------------------------------------- + when :tag + Onering::Logger.fatal!("Expected 1 parameters, got #{args.length}", "Onering::CLI::Assets") unless args.length > 0 + + if @opts[:query] + # doing this until a bulk field set endpoint is built + @api.list('id', { + :filter => @opts[:query] + }).collect{|i| @api.get("devices/#{i}/tag/#{args.join('/')}") } + + elsif @opts[:id] + @api.get("devices/#{@opts[:id]}/tag/#{args.join('/')}") + end + + return nil + + when :untag + Onering::Logger.fatal!("Expected 1 parameters, got #{args.length}", "Onering::CLI::Assets") unless args.length > 0 + + if @opts[:query] + # doing this until a bulk field set endpoint is built + @api.list('id', { + :filter => @opts[:query] + }).collect{|i| @api.get("devices/#{i}/untag/#{args.join('/')}") } + + elsif @opts[:id] + @api.get("devices/#{@opts[:id]}/untag/#{args.join('/')}") + end + + return nil else - Onering::Logger.fatal!("Unknown subcommand #{sc.inspect}", "Onering::CLI::Devices") + Onering::Logger.fatal!("Unknown subcommand #{sc.inspect}", "Onering::CLI::Assets") end end end end end \ No newline at end of file