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.
Class Method Summary collapse
Instance Method Summary collapse
- #default_option_parser(banner: "") ⇒ Object
- #host ⇒ 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.
22 23 24 25 26 27 |
# File 'lib/roby/app/scripts.rb', line 22 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.
20 21 22 |
# File 'lib/roby/app/scripts.rb', line 20 def app @app end |
Class Method Details
.run(*args, banner: "", &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/roby/app/scripts.rb', line 60 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
33 34 35 36 37 38 |
# File 'lib/roby/app/scripts.rb', line 33 def default_option_parser(banner: "") parser = OptionParser.new parser. = setup_option_parser(parser) parser end |
#host ⇒ Object
40 41 42 |
# File 'lib/roby/app/scripts.rb', line 40 def host @host_options.values_at(:host, :port) end |
#run(*args, banner: "", option_parser: default_option_parser(banner: banner)) {|interface| ... } ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/roby/app/scripts.rb', line 44 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 = Interface::V1.connect_with_tcp_to(host, port) yield(interface) end |
#setup_option_parser(parser) ⇒ Object
29 30 31 |
# File 'lib/roby/app/scripts.rb', line 29 def setup_option_parser(parser) Roby::Application.(parser, @host_options) end |