module TreasureData module Command class Runner def initialize @config_path = nil @apikey = nil @endpoint = nil @prog_name = nil @insecure = false end attr_accessor :apikey, :endpoint, :config_path, :prog_name, :insecure def run(argv=ARGV) require 'td/version' require 'td/compat_core' require 'optparse' $prog = @prog_name || File.basename($0) op = OptionParser.new op.version = TOOLBELT_VERSION op.banner = < e # known exceptions are rendered as simple error messages unless the # TD_TOOLBELT_DEBUG variable is set or the -v / --verbose option is used. # List of known exceptions: # => ParameterConfigurationError # => BulkImportExecutionError # => UpUpdateError # => ImportError require 'td/client/api' # => APIError # => ForbiddenError # => NotFoundError # => AuthError if ![ParameterConfigurationError, BulkImportExecutionError, UpdateError, ImportError, APIError, ForbiddenError, NotFoundError, AuthError].include?(e.class) || !ENV['TD_TOOLBELT_DEBUG'].nil? || $verbose show_backtrace "Error #{$!.class}: backtrace:", $!.backtrace end if $!.respond_to?(:api_backtrace) && $!.api_backtrace show_backtrace "Error backtrace from server:", $!.api_backtrace.split("\n") end $stdout.print "Error: " if [ForbiddenError, NotFoundError, AuthError].include?(e.class) $stdout.print "#{e.class} - " end $stdout.puts $!.to_s require 'socket' if e.is_a?(::SocketError) $stderr.puts <