Class: TConsole::Runner
- Inherits:
-
Object
- Object
- TConsole::Runner
- Defined in:
- lib/tconsole.rb
Class Method Summary collapse
-
.run(argv) ⇒ Object
Spawns a new environment.
Class Method Details
.run(argv) ⇒ Object
Spawns a new environment. Looks at the results of the environment to determine whether to stop or keep running
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tconsole.rb', line 21 def self.run(argv) stty_save = `stty -g`.chomp running = true trap("SIGINT", "IGNORE") trap("SIGTSTP", "IGNORE") # A little welcome puts puts "Welcome to tconsole (v#{TConsole::VERSION}). Type 'help' for help or 'exit' to quit." # set up the config Config.load_config(File.join(Dir.home, ".tconsole")) Config.load_config(File.join(Dir.pwd, ".tconsole")) config = Config.configure(argv) config_errors = config.validation_errors if config_errors.length > 0 puts puts config_errors.first exit(1) end # Set up our console input handling and history console = Console.new(config) # Start the server while running # ignore ctrl-c during load, since things can get kind of messy if we don't pipe_server = PipeServer.new config.trace("Forking test server.") server_pid = fork do pipe_server.callee! server = Server.new(config) while = pipe_server.read config.trace("Server Received Message: #{[:action]}") begin result = server.handle() pipe_server.write(result) rescue => e puts puts "An error occured: #{e.}" config.trace("===========") config.trace(e.backtrace.join("\n")) config.trace("===========") pipe_server.write(nil) end end end pipe_server.caller! wait_until = Time.now + 10 config.trace("Attempting to load environment.") pipe_server.write({:action => "load_environment"}) unless pipe_server.read puts "Couldn't load the test environment. Exiting." exit(1) end config.trace("Environment loaded successfully.") console.pipe_server = pipe_server running = console.read_and_execute console.pipe_server = nil Process.waitall end console.store_history puts puts "Exiting. Bye!" system("stty", stty_save); end |