fix infinite loop if CONT signal received while todo is empty
[arvados.git] / sdk / cli / bin / arv
index 4e2ab5f2dc2e975f641f59e0aa574d2781606fa1..aae9fce63c7a6e8474a5abb92c39c32357eec7e6 100755 (executable)
@@ -13,16 +13,30 @@ end
 if ARGV[0] == 'keep'
   ARGV.shift
   @sub = ARGV.shift
-  if @sub == 'ls' or @sub == 'get' or @sub == 'put' or @sub == 'less' then
-    exec(`which wh#{@sub}`.strip + ' ' + ARGV.join(' '))
+  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 less\n" +
+      "#{$0} keep check\n"
   end
-  exit
+  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'
@@ -124,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")
@@ -135,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
@@ -181,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
 
@@ -195,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