4 # arv tag add tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...]
5 # arv tag remove tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...]
6 # arv tag remove tag1 [tag2 ...] --all
10 "arv tag add tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" +
11 "arv tag remove tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" +
12 "arv tag remove --all\n"
15 def tag_add(tag, obj_uuid)
17 :api_token => ENV['ARVADOS_API_TOKEN'],
21 :head_uuid => obj_uuid,
25 result = $client.execute(:api_method => $arvados.links.create,
26 :body => request_body,
27 :authenticated => false)
30 results = JSON.parse result.body
31 rescue JSON::ParserError => e
32 $stderr.puts "Failed to parse server response:\n" + e.to_s
36 if results["errors"] then
37 $stderr.puts "Error: #{results["errors"][0]}"
44 def tag_remove(tag, obj_uuid=nil)
46 :api_token => ENV['ARVADOS_API_TOKEN'],
50 :head_uuid => obj_uuid,
54 return $client.execute(:api_method => $arvados.links.destroy,
55 :parameters => params,
56 :body => request_body,
57 :authenticated => false)
60 if RUBY_VERSION < '1.9.3' then
62 #{$0.gsub(/^\.\//,'')} requires Ruby version 1.9.3 or higher.
66 $arvados_api_version = ENV['ARVADOS_API_VERSION'] || 'v1'
67 $arvados_api_host = ENV['ARVADOS_API_HOST'] or
68 abort "#{$0}: fatal: ARVADOS_API_HOST environment variable not set."
69 $arvados_api_token = ENV['ARVADOS_API_TOKEN'] or
70 abort "#{$0}: fatal: ARVADOS_API_TOKEN environment variable not set."
71 $arvados_api_host_insecure = ENV['ARVADOS_API_HOST_INSECURE'] == 'yes'
75 require 'google/api_client'
81 #{$0}: fatal: some runtime dependencies are missing.
82 Try: gem install pp google-api-client json trollop
86 def debuglog(message, verbosity=1)
87 $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if $debuglevel >= verbosity
92 original_verbosity = $VERBOSE
95 $VERBOSE = original_verbosity
100 if $arvados_api_host_insecure or $arvados_api_host.match /local/
101 # You probably don't care about SSL certificate checks if you're
102 # testing with a dev server.
103 suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
106 class Google::APIClient
107 def discovery_document(api, version)
109 return @discovery_documents["#{api}:#{version}"] ||=
111 response = self.execute!(
112 :http_method => :get,
113 :uri => self.discovery_uri(api, version),
114 :authenticated => false
116 response.body.class == String ? JSON.parse(response.body) : response.body
121 global_opts = Trollop::options do
122 banner "arvados cli client"
123 opt :dry_run, "Don't actually do anything", :short => "-n"
124 opt :verbose, "Print some things on stderr", :short => "-v"
125 opt :uuid, "Return the UUIDs of the objects in the response, one per line (default)", :short => nil
126 opt :json, "Return the entire response received from the API server, as a JSON object", :short => "-j"
127 opt :human, "Return the response received from the API server, as a JSON object with whitespace added for human consumption", :short => "-h"
128 opt :pretty, "Synonym of --human", :short => nil
129 opt :yaml, "Return the response received from the API server, in YAML format", :short => "-y"
130 stop_on ['add', 'remove']
133 p = Trollop::Parser.new do
135 "Remove this tag from all objects under your ownership. Only valid with `tag remove'.",
138 "The UUID of an object to which this tag operation should be applied.",
144 $options = Trollop::with_standard_exception_handling p do
148 if $options[:all] and ARGV[0] != 'remove'
152 # Set up the API client.
154 $client ||= Google::APIClient.
155 new(:host => $arvados_api_host,
156 :application_name => File.split($0).last,
157 :application_version => $application_version.to_s)
158 $arvados = $client.discovered_api('arvados', $arvados_api_version)
165 $options[:object].each do |obj|
166 results.push(tag_add(tag, obj))
171 if $options[:all] then
172 results.push(tag_remove(tag))
174 $options[:object].each do |obj|
175 results.push(tag_remove(tag, obj))
183 if global_opts[:human] or global_opts[:pretty] then
184 puts Oj.dump(results, :indent => 1)
185 elsif global_opts[:yaml] then
187 elsif global_opts[:json] then
188 puts Oj.dump(results)
192 if r["items"] and r["kind"].match /list$/i
193 r['items'].each do |i| puts i['uuid'] end
195 abort("Response did not include a uuid:\n" +
196 Oj.dump(r, :indent => 1) +