Class: Roby::App::Scripts::InterfaceScript
- Defined in:
- lib/roby/app/scripts.rb
Overview
Common implementation for scripts whose main functionality requires to connect to Roby’s remote interface
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
Instance Method Summary collapse
- #default_option_parser(banner: "") ⇒ Object
-
#initialize(app = Roby.app, default_host: app.shell_interface_host || 'localhost', default_port: app.shell_interface_port || Interface::DEFAULT_PORT) ⇒ InterfaceScript
constructor
A new instance of InterfaceScript.
- #run(*args, banner: "", option_parser: default_option_parser(banner: banner)) {|interface| ... } ⇒ Object
- #setup_option_parser(parser) ⇒ Object
Constructor Details
#initialize(app = Roby.app, default_host: app.shell_interface_host || 'localhost', default_port: app.shell_interface_port || Interface::DEFAULT_PORT) ⇒ InterfaceScript
Returns a new instance of InterfaceScript.
21 22 23 24 25 26 |
# File 'lib/roby/app/scripts.rb', line 21 def initialize(app = Roby.app, default_host: app.shell_interface_host || 'localhost', default_port: app.shell_interface_port || Interface::DEFAULT_PORT) @app = app @host_options = Hash[host: default_host, port: default_port] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
18 19 20 |
# File 'lib/roby/app/scripts.rb', line 18 def app @app end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
19 20 21 |
# File 'lib/roby/app/scripts.rb', line 19 def host @host end |
Class Method Details
.run(*args, banner: '', &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roby/app/scripts.rb', line 57 def self.run(*args, banner: '', &block) Roby.display_exception do begin new.run(*args, banner: , &block) rescue Roby::Interface::ConnectionError => e Robot.fatal e. rescue Interrupt Robot.warn "Interrupted by user" end end end |
Instance Method Details
#default_option_parser(banner: "") ⇒ Object
32 33 34 35 36 37 |
# File 'lib/roby/app/scripts.rb', line 32 def default_option_parser(banner: "") parser = OptionParser.new parser. = setup_option_parser(parser) parser end |
#run(*args, banner: "", option_parser: default_option_parser(banner: banner)) {|interface| ... } ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/roby/app/scripts.rb', line 43 def run(*args, banner: "", option_parser: default_option_parser(banner: )) app.guess_app_dir app.shell app.single app.load_base_config args = option_parser.parse(args) host, port = self.host interface = Roby::Interface.connect_with_tcp_to(host, port) yield(interface) end |
#setup_option_parser(parser) ⇒ Object
28 29 30 |
# File 'lib/roby/app/scripts.rb', line 28 def setup_option_parser(parser) Roby::Application.(parser, @host_options) end |