class Roby::App::Scripts::InterfaceScript

Common implementation for scripts whose main functionality requires to connect to Roby's remote interface

@example basic usage

require 'roby/app/scripts'
Roby::App::Scripts::InterfaceScript.run(*ARGV) do |interface|
    # Do stuff with the roby interface
end

Attributes

app[R]
host[R]

Public Class Methods

new(app = Roby.app, default_host: app.shell_interface_host || 'localhost', default_port: app.shell_interface_port || Interface::DEFAULT_PORT) click to toggle source
# 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
run(*args, banner: '', &block) click to toggle source
# File lib/roby/app/scripts.rb, line 57
def self.run(*args, banner: '', &block)
    Roby.display_exception do
        begin
            new.run(*args, banner: banner, &block)
        rescue Roby::Interface::ConnectionError => e
            Robot.fatal e.message
        rescue Interrupt
            Robot.warn "Interrupted by user"
        end
    end
end

Public Instance Methods

default_option_parser(banner: "") click to toggle source
# File lib/roby/app/scripts.rb, line 32
def default_option_parser(banner: "")
    parser = OptionParser.new
    parser.banner = banner
    setup_option_parser(parser)
    parser
end
run(*args, banner: "", option_parser: default_option_parser(banner: banner)) { |interface| ... } click to toggle source
# File lib/roby/app/scripts.rb, line 43
def run(*args, banner: "",
    option_parser: default_option_parser(banner: 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) click to toggle source
# File lib/roby/app/scripts.rb, line 28
def setup_option_parser(parser)
    Roby::Application.host_options(parser, @host_options)
end