processor/command/quit.rb in trepanning-0.1.3 vs processor/command/quit.rb in trepanning-0.1.4

- old
+ new

@@ -1,7 +1,7 @@ -# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net> -require_relative 'base/cmd' +# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net> +require_relative '../command' class Trepan::Command::QuitCommand < Trepan::Command unless defined?(HELP) NAME = File.basename(__FILE__, '.rb') HELP = <<-HELP @@ -14,11 +14,11 @@ passed to exit() - presumably the return code that will be passed back to the OS. If no exit code is given, 0 is used. Examples: #{NAME} # quit prompting if we are interactive - #{NAME} conditionally # quit without prompting + #{NAME} unconditionally # quit without prompting #{NAME}! # same as above #{NAME} 0 # same as "quit" #{NAME}! 1 # unconditional quit setting exit code 1 See also the commands "exit" and "kill". @@ -34,11 +34,11 @@ # whether exit! or exit is used. # This method runs the command def run(args) unconditional = - if args.size > 1 && args[1] == 'unconditionally' + if args.size > 1 && args[-1] == 'unconditionally' args.shift true elsif args[0][-1] == '!' true else @@ -46,20 +46,31 @@ end unless unconditional || confirm('Really quit?', false) msg('Quit not confirmed.') return end - - exitrc = (args.size > 1) ? exitrc = Integer(args[1]) rescue 0 : 0 + + if (args.size > 1) + if args[1] =~ /\d+/ + exitrc = args[1].to_i; + else + errmsg "Bad an Integer return type \"#{args[1]}\""; + return; + end + else + exitrc = 0 + end # No graceful way to stop threads... @proc.finalize @proc.dbgr.intf[-1].finalize exit exitrc end end if __FILE__ == $0 require_relative '../mock' dbgr, cmd = MockDebugger::setup - fork { cmd.run([cmd.name]) } + Process.fork { cmd.run([cmd.name]) } if + Process.respond_to?(:fork) + cmd.run([cmd.name, 'foo']) cmd.run([cmd.name, '5']) end