class Roby::Interface::CommandLibrary

Objects that hold a set of commands

Constants

InterfaceCommands

Attributes

app[R]

@return [Roby::Application] the application

subcommands[R]

@return [Hash<String,CommandInterface>] the set of command subcommands

attached to this command interface

Public Class Methods

command(name, *info) click to toggle source

Declares a command for this interface

# File lib/roby/interface/command_library.rb, line 11
def command(name, *info)
    arguments = if info.last.kind_of?(Hash) then info.pop
                else Hash.new
                end

    arguments = arguments.map_key do |name, _|
        name.to_sym
    end
    arguments = arguments.map_value do |name, description|
        CommandArgument.new(name.to_sym, Array(description))
    end
    commands[name.to_sym] = Command.new(name.to_sym, info, arguments)
end
new(app) click to toggle source
# File lib/roby/interface/command_library.rb, line 49
def initialize(app)
    @app = app
    @subcommands = Hash.new

    self.class.each_subcommand do |name, (interface_model, description)|
        subcommand(name, interface_model.new(app), description)
    end
end
subcommand(name, interface, *description) click to toggle source

Adds another interface object a subcommand of this command interface

@param [String] name the subcommand name. The commands will be

available as name.command_name

@param [Model<CommandInterface>] interface the command interface model

# File lib/roby/interface/command_library.rb, line 31
def subcommand(name, interface, *description)
    subcommands[name] = [interface, description]
    define_method name do
        subcommands[name].first
    end
end

Public Instance Methods

commands() click to toggle source

The set of commands that exist on self and on its subcommands

@return [Hash<String,InterfaceCommands>] the set of commands of

self (with key '') and of its subcommands (where the key is not
empty)
# File lib/roby/interface/command_library.rb, line 83
def commands
    result = Hash['' => InterfaceCommands.new('', nil, self.class.commands)]
    each_subcommand do |name, interface, description|
        result[name] = InterfaceCommands.new(name, description, interface.commands)
    end
    result
end
each_subcommand() { |name, interface, description| ... } click to toggle source

Enumerate the subcommands available on this interface

@yieldparam [String] name the subcommand name

# File lib/roby/interface/command_library.rb, line 69
def each_subcommand
    return enum_for(__method__) if !block_given?
    subcommands.each do |name, (interface, description)|
        yield(name, interface, description)
    end
end
execution_engine() click to toggle source

@return [Roby::ExecutionEngine] the {#plan}'s engine

# File lib/roby/interface/command_library.rb, line 44
def execution_engine; plan.execution_engine end
plan() click to toggle source

@return [Roby::Plan] the {#app}'s plan

# File lib/roby/interface/command_library.rb, line 42
def plan; app.plan end
subcommand(name, interface, description) click to toggle source

Declare a subcommand on this interface

Unless with {CommandLibrary.subcommand}, the interface must already be instanciated

# File lib/roby/interface/command_library.rb, line 62
def subcommand(name, interface, description)
    subcommands[name] = [interface, description]
end