diff --git a/lib/td/command/account.rb b/lib/td/command/account.rb index 6a352124..9fdfcf2f 100644 --- a/lib/td/command/account.rb +++ b/lib/td/command/account.rb @@ -93,7 +93,7 @@ def account(op) $stdout.puts "Authenticated successfully." - conf ||= Config.new + conf ||= Config::ConfigFile.new conf["account.user"] = user_name conf["account.apikey"] = client.apikey conf['account.endpoint'] = endpoint if endpoint diff --git a/lib/td/command/apikey.rb b/lib/td/command/apikey.rb index 3993d14f..c5967e1f 100644 --- a/lib/td/command/apikey.rb +++ b/lib/td/command/apikey.rb @@ -50,7 +50,7 @@ def apikey_set(op) end end - conf ||= Config.new + conf ||= Config::ConfigFile.new conf.delete("account.user") conf["account.apikey"] = apikey conf.save diff --git a/lib/td/command/runner.rb b/lib/td/command/runner.rb index 8ee73611..32a19de4 100644 --- a/lib/td/command/runner.rb +++ b/lib/td/command/runner.rb @@ -1,41 +1,42 @@ module TreasureData -module Command - -class Runner - def initialize - @config_path = nil - @apikey = nil - @endpoint = nil - @import_endpoint = nil - @prog_name = nil - @insecure = false - end - - attr_accessor :apikey, :endpoint, :import_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, AlreadyExistsError, WorkflowError].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 + require 'td/command/list' + if defined?(Encoding) + #Encoding.default_internal = 'UTF-8' if Encoding.respond_to?(:default_internal) + Encoding.default_external = 'UTF-8' if Encoding.respond_to?(:default_external) + end - $stdout.print "Error: " - if [ForbiddenError, NotFoundError, AuthError].include?(e.class) - $stdout.print "#{e.class} - " - end - $stdout.puts $!.to_s + method, cmd_req_connectivity = Command::List.get_method(cmd) + unless method + $stderr.puts "'#{cmd}' is not a td command. Run '#{$prog}' to show the list." + Command::List.show_guess(cmd) + return 1 + end - require 'socket' - if e.is_a?(::SocketError) - $stderr.puts < 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, AlreadyExistsError, WorkflowError].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 <