lib/cli/runner.rb in af-0.3.18.12 vs lib/cli/runner.rb in af-0.3.19.beta.1

- old
+ new

@@ -46,10 +46,11 @@ opts.on('--all') { @options[:all] = true } # generic tracing and debugging opts.on('-t [TKEY]') { |tkey| @options[:trace] = tkey || true } opts.on('--trace [TKEY]') { |tkey| @options[:trace] = tkey || true } + opts.on('--crash') { @options[:crash] = true } # start application in debug mode opts.on('-d [MODE]') { |mode| @options[:debug] = mode || "run" } opts.on('--debug [MODE]') { |mode| @options[:debug] = mode || "run" } @@ -96,11 +97,11 @@ opts.on('--noframework') { @options[:noframework] = true } opts.on('--canary') { @options[:canary] = true } # Proxying for another user, requires admin privileges opts.on('-u PROXY') { |proxy| @options[:proxy] = proxy } - + # Select infrastructure opts.on('--infra INFRA') { |infra| @options[:infra] = infra } opts.on_tail('--options') { puts "#{opts}\n"; exit } end @@ -283,19 +284,19 @@ if @args.size == 1 set_cmd(:apps, :files, 1) else set_cmd(:apps, :files, 2) end - + when 'download' usage('af download <appname> [path]') if @args.size == 1 set_cmd(:apps, :download, 1) else set_cmd(:apps, :download, 2) end - + when 'pull' usage('af pull <appname> [path]') if @args.size == 1 set_cmd(:apps, :pull, 1) else @@ -387,20 +388,20 @@ set_cmd(:services, :clone_services, 2) when 'export-service' usage('af export-service <service-name>') set_cmd(:services, :export_service, 1) - + when 'import-service' usage('af import-service <service-name> <url>') set_cmd(:services, :import_service, 2) - + when 'clone' usage('af clone <src-app> <dest-app> [<infra>]') set_cmd(:apps, :clone, 2) if @args.size == 2 set_cmd(:apps, :clone, 3) if @args.size == 3 - + when 'aliases' usage('af aliases') set_cmd(:misc, :aliases) when 'alias' @@ -482,11 +483,49 @@ def usage_error(msg = nil) @usage_error = msg if msg @usage_error end + def crash_log(e, message = nil) + @finish_time = Time.now + diff = @finish_time - @start_time + + if message != nil + message = "#{message} (#{e.message})" + else + message = e.message + end + + say message.red + + @options[:password] = "".rjust(@options[:password].length, '*') if @options[:password] + + log = "" + log += "Action: #{@action}\n" + log += "Arguments: #{@args.join(' ')}\n" if "#{@action}" != 'environment_add' + log += "Options: #{@options.to_json}\n" + log += "Execution Time: %.2fs\n" % diff + log += "Target: #{VMC::Cli::Config.target_url}\n" + log += "Client: v#{VMC::Cli::VERSION}\n" + log += "Platform: #{RUBY_PLATFORM} - Ruby:#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}\n" + log += "Type: #{e.class}\n" + log += "Message: #{e.message}\n" + log += "Stack Trace:\n" + e.backtrace.each do |trace| + log += " #{trace}\n" + end + + if @options[:crash] == true + say "--- #{File.expand_path(VMC::Cli::Config::CRASH_FILE)} ---" + say log + end + + VMC::Cli::Config.store_crash(log) + end + def run + @start_time = Time.now trap('TERM') { print "\nTerminated\n"; exit(false)} parse_options! @@ -510,51 +549,55 @@ display basic_usage exit(false) end rescue OptionParser::InvalidOption => e - puts(e.message.red) + crash_log(e) puts("\n") puts(basic_usage) @exit_status = false rescue OptionParser::AmbiguousOption => e - puts(e.message.red) + crash_log(e) puts("\n") puts(basic_usage) @exit_status = false + rescue VMC::Cli::Command::User::InvalidLogin => e + crash_log(e) + @exit_status = false + rescue VMC::Client::BadTarget => e + crash_log(e, "Problem with login to '#{VMC::Cli::Config.target_url}', try again or register for an account.") + @exit_status = false rescue VMC::Client::AuthError => e if VMC::Cli::Config.auth_token.nil? puts "Login Required".red else puts "Not Authorized".red end @exit_status = false rescue VMC::Client::TargetError, VMC::Client::NotFound, VMC::Client::BadTarget => e - puts e.message.red + crash_log(e) @exit_status = false rescue VMC::Client::HTTPException => e - puts e.message.red + crash_log(e, "There was a problem connecting to the target. Please try again in a few moments.") @exit_status = false rescue VMC::Cli::GracefulExit => e # Redirected commands end up generating this exception (kind of goto) rescue VMC::Cli::CliExit => e - puts e.message.red + crash_log(e) @exit_status = false rescue VMC::Cli::CliError => e - say("Error #{e.error_code}: #{e.message}".red) + crash_log(e, "Error #{e.error_code}: #{e.message}") @exit_status = false rescue SystemExit => e @exit_status = e.success? rescue SyntaxError => e - puts e.message.red - puts e.backtrace + crash_log(e) @exit_status = false rescue Interrupt => e - say("\nInterrupted".red) + crash_log(e, "Interrupted") @exit_status = false rescue Exception => e - puts e.message.red - puts e.backtrace + crash_log(e) @exit_status = false ensure say("\n") @exit_status == true if @exit_status.nil? if @options[:verbose]