Sha256: 3488a38145d41d4e1fa06a77454a1eaeeba5dca4fd99199ce9d60e6974446a96

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

# Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
require_relative 'base/cmd'
class Trepan::Command::QuitCommand < Trepan::Command

  unless defined?(HELP)
    NAME = File.basename(__FILE__, '.rb')
    HELP = <<-HELP
#{NAME}[!] [unconditionally] [exit code] 

gentle termination

The program being debugged is exited via exit() which runs the Kernel
at_exit finalizers. If a return code is given, that is the return code
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}!                # same as above
  #{NAME} 0               # same as "quit"
  #{NAME}! 1              # unconditional quit setting exit code 1

See also the commands "exit" and "kill".
    HELP

    ALIASES      = %W(#{NAME}! q q!)
    CATEGORY     = 'support'
    MAX_ARGS     = 2  # Need at most this many
    SHORT_HELP  = 'Quit program - gently'
  end

  # FIXME: Combine 'quit' and 'exit'. The only difference is
  # whether exit! or exit is used.

  # This method runs the command
  def run(args)
    unconditional = 
      if args.size > 1 && args[1] == 'unconditionally'
        args.shift
        true
      elsif args[0][-1] == '!'
        true
      else
        false
      end
    unless unconditional || confirm('Really quit?', false)
      msg('Quit not confirmed.')
      return
    end

    exitrc = (args.size > 1) ? exitrc = Integer(args[1]) rescue 0 : 0
    # 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]) }
  cmd.run([cmd.name, '5'])
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trepanning-0.1.3 processor/command/quit.rb