X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7a5ae650df19557a5fa88a8a1ae73ae07cad01cf..92e0d49360dfdb6c0da4ec6904fa1cf33ba8c2fb:/sdk/cli/bin/arv?ds=sidebyside diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv index 052aecb8fa..0abd976fc5 100755 --- a/sdk/cli/bin/arv +++ b/sdk/cli/bin/arv @@ -10,6 +10,35 @@ if RUBY_VERSION < '1.9.3' then EOS end +if ARGV[0] == 'keep' + ARGV.shift + @sub = ARGV.shift + if ['ls', 'get', 'put', 'less', 'check'].index @sub then + exec `which wh#{@sub}`.strip, *ARGV + else + puts "Usage: \n" + + "#{$0} keep ls\n" + + "#{$0} keep get\n" + + "#{$0} keep put\n" + + "#{$0} keep less\n" + + "#{$0} keep check\n" + end + abort +end + +if ARGV[0] == 'pipeline' + ARGV.shift + @sub = ARGV.shift + if ['run'].index @sub then + exec `which arv-run-pipeline-instance`.strip, *ARGV + else + puts "Usage: \n" + + "#{$0} pipeline run [...]\n" + + "(see arv-run-pipeline-instance --help for details)\n" + end + abort +end + ENV['ARVADOS_API_VERSION'] ||= 'v1' if not ENV.include?('ARVADOS_API_HOST') or not ENV.include?('ARVADOS_API_TOKEN') then @@ -71,7 +100,17 @@ class Google::APIClient end end -client = Google::APIClient.new(:host => ENV['ARVADOS_API_HOST'], :application_name => 'arvados-cli', :application_version => '1.0') +class ArvadosClient < Google::APIClient + def execute(*args) + if args.last.is_a? Hash + args.last[:headers] ||= {} + args.last[:headers]['Accept'] ||= 'application/json' + end + super(*args) + end +end + +client = ArvadosClient.new(:host => ENV['ARVADOS_API_HOST'], :application_name => 'arvados-cli', :application_version => '1.0') arvados = client.discovered_api('arvados', ENV['ARVADOS_API_VERSION']) def to_boolean(s) @@ -109,7 +148,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") @@ -120,9 +159,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 @@ -166,10 +213,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 @@ -180,7 +228,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