require_relative 'api_runner' module Unipept::Commands class Taxa2Tree < ApiRunner def initialize(args, opts, cmd) super # JSON is the default format for this command args[:format] = 'json' unless args[:format] unless %w[url html json].include? args[:format] warn "Format #{args[:format]} is not supported by taxa2tree. Use html, url or json (default)." exit 1 end if options[:format] == 'html' # Overwrite the URL for this command, since it's possible that it uses HTML generated by the server. @url = "#{@host}/api/v1/#{cmd.name}.html" elsif args[:format] == 'url' @link = true end end def required_fields ['taxon_id'] end def batch_size return arguments.length unless arguments.empty? return File.foreach(options[:input]).inject(0) { |c, _| c + 1 } if options[:input] @stdin_contents = $stdin.readlines @stdin_contents.length end def input_iterator return arguments.each unless arguments.empty? return File.foreach(options[:input]) if options[:input] @stdin_contents.each end protected def filter_result(response) return response if response.start_with?('