X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/308a6da1a9fd716f3957b116110a932c08aefafe..2b7d05cdf4e054024607b859bd6fb41e04855bfa:/sdk/cli/bin/arv-tag diff --git a/sdk/cli/bin/arv-tag b/sdk/cli/bin/arv-tag index 4ee6770f77..f709020fc7 100755 --- a/sdk/cli/bin/arv-tag +++ b/sdk/cli/bin/arv-tag @@ -1,23 +1,32 @@ #! /usr/bin/env ruby +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 # arv tag usage: # arv tag add tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...] # arv tag remove tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...] # arv tag remove tag1 [tag2 ...] --all -def usage - abort "Usage:\n" + - "arv tag add tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" + - "arv tag remove tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" + +def usage_string + return "\nUsage:\n" + + "arv tag add tag1 [tag2 ...] --object object_uuid1 [object_uuid2...]\n" + + "arv tag remove tag1 [tag2 ...] --object object_uuid1 [object_uuid2...]\n" + "arv tag remove --all\n" end +def usage + abort usage_string +end + def api_call(method, parameters:{}, request_body:{}) - request_body[:api_token] = ENV['ARVADOS_API_TOKEN'] result = $client.execute(:api_method => method, :parameters => parameters, :body_object => request_body, - :authenticated => false) + :authenticated => false, + :headers => { + authorization: "OAuth2 #{ENV['ARVADOS_API_TOKEN']}", + }) begin results = JSON.parse result.body @@ -95,7 +104,8 @@ $arvados_api_host = ENV['ARVADOS_API_HOST'] or abort "#{$0}: fatal: ARVADOS_API_HOST environment variable not set." $arvados_api_token = ENV['ARVADOS_API_TOKEN'] or abort "#{$0}: fatal: ARVADOS_API_TOKEN environment variable not set." -$arvados_api_host_insecure = ENV['ARVADOS_API_HOST_INSECURE'] == 'yes' +$arvados_api_host_insecure = %w(1 true yes). + include?((ENV['ARVADOS_API_HOST_INSECURE'] || "").downcase) begin require 'rubygems' @@ -103,11 +113,11 @@ begin require 'json' require 'pp' require 'oj' - require 'trollop' + require 'optimist' rescue LoadError abort <<-EOS #{$0}: fatal: some runtime dependencies are missing. -Try: gem install pp google-api-client json trollop +Try: gem install pp google-api-client json optimist EOS end @@ -146,8 +156,9 @@ class Google::APIClient end end -global_opts = Trollop::options do - banner "arvados cli client" +global_opts = Optimist::options do + banner usage_string + banner "" 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 @@ -158,7 +169,7 @@ global_opts = Trollop::options do stop_on ['add', 'remove'] end -p = Trollop::Parser.new do +p = Optimist::Parser.new do opt(:all, "Remove this tag from all objects under your ownership. Only valid with `tag remove'.", :short => :none) @@ -169,7 +180,7 @@ p = Trollop::Parser.new do :short => :o) end -$options = Trollop::with_standard_exception_handling p do +$options = Optimist::with_standard_exception_handling p do p.parse ARGV end