Fix sending resource body to server.
[arvados.git] / sdk / cli / bin / arv
index e7d70d8b5692bf31db81f31c7587b1de8b098001..4db95c846f982b368655f45f1eb0e8597c98d270 100755 (executable)
@@ -10,6 +10,26 @@ if RUBY_VERSION < '1.9.3' then
   EOS
 end
 
+# read authentication data from ~/.arvados if present
+lineno = 0
+config_file = File.expand_path('~/.arvados')
+if File.exist? config_file then
+  File.open(config_file, 'r').each do |line|
+    lineno = lineno + 1
+    # skip comments
+    if line.match('^\s*#') then
+      next
+    end
+    var, val = line.chomp.split('=', 2)
+    # allow environment settings to override config files.
+    if var and val
+      ENV[var] ||= val
+    else
+      warn "#{config_file}: #{lineno}: could not parse `#{line}'"
+    end
+  end
+end
+
 case ARGV[0]
 when 'keep'
   ARGV.shift
@@ -40,6 +60,9 @@ when 'pipeline'
       "(see arv-run-pipeline-instance --help for details)\n"
   end
   abort
+when 'tag'
+  ARGV.shift
+  exec `which arv-tag`.strip, *ARGV
 end
 
 ENV['ARVADOS_API_VERSION'] ||= 'v1'
@@ -228,7 +251,7 @@ def parse_arguments(discovery_document)
   discovered_params.each do |k,v|
     k = k.to_sym
     if ['object', 'array'].index(v["type"]) and method_opts.has_key? k
-      if method_opts[k].match /^\//
+      if method_opts[k].andand.match /^\//
         method_opts[k] = File.open method_opts[k], 'rb' do |f| f.read end
       end
     end
@@ -252,7 +275,7 @@ 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)
+    resource_schema => resource_body
   }
 else
   request_body = {}