in api-reference-examples/ruby/te-tag-query/TETagQuery.rb [1076:1156]
def handle(args, options)
options['dryRun'] = false;
options['descriptorIDsFromStdin'] = false;
postParams = {}
# Local keystroke-saver for this enum
names = ThreatExchange::TENet::POST_PARAM_NAMES
loop do
break if args.length == 0
break unless args[0][0] == '-'
option = args.shift
if option == '-h'
self.usage(0)
elsif option == '--help'
self.usage(0)
elsif option == '--dry-run'
options['dryRun'] = true
elsif option == '-N'
options['descriptorIDsFromStdin'] = true;
elsif option == '-n'
self.usage(1) unless args.length >= 1
postParams[names[:descriptor_id]] = args.shift;
elsif option == '-i' || option == '--indicator'
self.usage(1) unless args.length >= 1
postParams[names[:indicator]] = args.shift;
elsif option == '-t' || option == '--type'
self.usage(1) unless args.length >= 1
postParams[names[:type]] = args.shift;
elsif option == '--tags'
self.usage(1) unless args.length >= 1
postParams[names[:tags]] = args.shift;
else
handled, args = self.commonPosterOptionCheck(option, args, postParams)
if not handled
$stderr.puts "#{$0} #{@verbName}: unrecognized option #{option}"
exit 1
end
end
end
if args.length > 0
$stderr.puts "#{$0} #{@verbName}: extraneous argument(s) \"#{args.join(' ')}\"."
exit 1
end
if options['descriptorIDsFromStdin']
unless postParams[names[:descriptor_id]].nil?
$stderr.puts "#{$0} #{@verbName}: only one of -N and -n must be supplied."
exit 1
end
$stdin.readlines.each do |line|
postParams[names[:descriptor_id]] = line.chomp
self.copySingle(
postParams,
verbose: options['verbose'],
showURLs: options['showURLs'],
dryRun: options['dryRun'],
)
end
else
if postParams[names[:descriptor_id]].nil?
$stderr.puts "#{$0} #{@verbName}: exactly one of -N and -n must be supplied."
exit 1
end
self.copySingle(
postParams,
verbose: options['verbose'],
showURLs: options['showURLs'],
dryRun: options['dryRun