Class: Tap::Prompt

Inherits:
App::Api show all
Defined in:
lib/tap/prompt.rb

Overview

:startdoc::prompt

A prompt to signal a running app. Any signals that return app (ie /run /stop /terminate) will exit the prompt.

Instance Attribute Summary

Attributes inherited from App::Api

#app

Instance Method Summary collapse

Methods inherited from App::Api

#associations, build, help, inherited, #initialize, parse, parse!, parser, #to_spec

Methods included from Signals

#signal, #signal?

Methods included from Signals::ModuleMethods

included

Constructor Details

This class inherits a constructor from Tap::App::Api

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tap/prompt.rb', line 12

def call
  puts "starting prompt (help for help):"
  loop do
    begin
      line = Readline.readline('--/', true).strip
      next if line.empty?

      args = Shellwords.shellwords(line)
      "/#{args.shift}" =~ Tap::Parser::SIGNAL

      result = app.call('obj' => $1, 'sig' => $2, 'args' => args)
      if result == app
        break
      else
        puts "=> #{result}"
      end
    rescue
      puts $!.message
      puts $!.backtrace if app.debug?
    end
  end
end