X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e0e53a773badd37106a3bed4022e9f3d7303e32a..8e1a765ae82afa02aa169d1639d8f442eb2fab47:/sdk/cli/bin/arv diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv index fbd246ebf0..aae9fce63c 100755 --- a/sdk/cli/bin/arv +++ b/sdk/cli/bin/arv @@ -138,7 +138,7 @@ def parse_arguments(discovery_document) discovered_params.each do |k,v| opts = Hash.new() opts[:type] = v["type"].to_sym if v.include?("type") - if [:datetime, :text, :object].index opts[:type] + if [:datetime, :text, :object, :array].index opts[:type] opts[:type] = :string # else trollop bork end opts[:default] = v["default"] if v.include?("default") @@ -149,9 +149,17 @@ def parse_arguments(discovery_document) description = ' ' + v["description"] if v.include?("description") opt k.to_sym, description, opts end + body_object = discovery_document["resources"][resource_arg.pluralize]["methods"][method]["request"] + if body_object and discovered_params[resource_arg].nil? + is_required = true + if body_object["required"] == false + is_required = false + end + opt resource_arg.to_sym, "#{resource_arg} (request body)", required: is_required, type: :string + end end discovered_params.each do |k,v| - if v["type"] == "object" and method_opts.has_key? k + if ['object', 'array'].index(v["type"]) and method_opts.has_key? k method_opts[k] = JSON.parse method_opts[k] end end @@ -195,10 +203,11 @@ def parse_arguments(discovery_document) end end - return resource_arg.pluralize, method, method_opts, global_opts, ARGV + return resource_arg, method, method_opts, global_opts, ARGV end -controller, method, method_opts, global_opts, remaining_opts = parse_arguments(arvados.discovery_document) +resource_schema, method, method_opts, global_opts, remaining_opts = parse_arguments(arvados.discovery_document) +controller = resource_schema.pluralize api_method = 'arvados.' + controller + '.' + method @@ -209,7 +218,20 @@ if global_opts[:dry_run] exit end -result = client.execute :api_method => eval(api_method), :parameters => { :api_token => ENV['ARVADOS_API_TOKEN'] }.merge(method_opts), :authenticated => false +request_parameters = {}.merge(method_opts) +resource_body = request_parameters.delete(resource_schema.to_sym) +if resource_body + request_body = { + resource_schema => JSON.parse(resource_body) + } +else + request_body = {} +end +request_body[:api_token] = ENV['ARVADOS_API_TOKEN'] +result = client.execute(:api_method => eval(api_method), + :parameters => request_parameters, + :body => request_body, + :authenticated => false) results = JSON.parse result.body if results["errors"] then