more specific info about VMs page
[arvados.git] / sdk / cli / arv
index 6b415acbfb89863da72d953859d9a60a3106fc79..ee42048466cabe4bb82cf5f1984bb367215c0700 100755 (executable)
@@ -25,15 +25,13 @@ begin
   require 'pp'
   require 'trollop'
   require 'andand'
+  require 'oj'
 rescue LoadError
   abort <<-EOS
 
 Please install all required gems: 
 
-  google-api-client
-  json
-  trollop
-  andand
+  gem install google-api-client json trollop andand oj
 
   EOS
 end
@@ -49,7 +47,9 @@ module Kernel
 end
 
 # do this if you're testing with a dev server and you don't care about SSL certificate checks:
-suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
+if ENV['ARVADOS_API_HOST_INSECURE']
+  suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
+end
 
 class Google::APIClient
  def discovery_document(api, version)
@@ -65,7 +65,7 @@ class Google::APIClient
  end
 end
 
-client = Google::APIClient.new(:host => ENV['ARVADOS_API_HOST'], :application_name => 'wh-cli', :application_version => '1.0')
+client = Google::APIClient.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)
@@ -84,8 +84,9 @@ def parse_arguments(discovery_document)
     opt :dry_run, "Don't actually do anything", :short => "-n"
     opt :verbose, "Print some things on stderr", :short => "-v"
     opt :uuid, "Return the UUIDs of the objects in the response, one per line (default)", :short => nil
-    opt :json, "Return the raw json received from the API server", :short => "-j"
-    opt :jsonhuman, "Return the raw json received from the API server, formatted for human consumption", :short => "-h"
+    opt :json, "Return the entire response received from the API server, as a JSON object", :short => "-j"
+    opt :human, "Return the response received from the API server, as a JSON object with whitespace added for human consumption", :short => "-h"
+    opt :pretty, "Synonym of --human", :short => nil
     stop_on resource_types
   end
   
@@ -180,10 +181,10 @@ if results["errors"] then
   abort "Error: #{results["errors"][0]}"
 end
 
-if global_opts[:json] then
-  puts results.to_s
-elsif global_opts[:jsonhuman] then
-  puts results.pretty_inspect()
+if global_opts[:human] or global_opts[:pretty] then
+  puts Oj.dump(results, :indent => 1)
+elsif global_opts[:json] then
+  puts Oj.dump(results)
 elsif results["items"] and results["kind"].match /list$/i
   results['items'].each do |i| puts i['uuid'] end
 else