Class: Roby::Interface::CommandLibrary

Inherits:
Object
  • Object
show all
Extended by:
MetaRuby::Attributes
Defined in:
lib/roby/interface/command_library.rb

Overview

Objects that hold a set of commands

Direct Known Subclasses

App::Debug, Interface

Defined Under Namespace

Classes: InterfaceCommands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CommandLibrary

Returns a new instance of CommandLibrary.



49
50
51
52
53
54
55
56
# 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

Instance Attribute Details

#appRoby::Application (readonly)

Returns the application.

Returns:

  • the application



40
41
42
# File 'lib/roby/interface/command_library.rb', line 40

def app
  @app
end

#subcommandsHash<String,CommandInterface> (readonly)

Returns the set of command subcommands attached to this command interface.

Returns:

  • the set of command subcommands attached to this command interface



47
48
49
# File 'lib/roby/interface/command_library.rb', line 47

def subcommands
  @subcommands
end

Class Method Details

.command(name, *info) ⇒ Object

Declares a command for this interface



11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

.subcommand(name, interface, *description) ⇒ Object

Adds another interface object a subcommand of this command interface

Parameters:

  • the subcommand name. The commands will be available as name.command_name

  • the command interface model



31
32
33
34
35
36
# 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

Instance Method Details

#commandsHash<String,InterfaceCommands>

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

Returns:

  • the set of commands of self (with key ”) and of its subcommands (where the key is not empty)



83
84
85
86
87
88
89
# 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| ... } ⇒ Object

Enumerate the subcommands available on this interface

Yield Parameters:

  • name (String)

    the subcommand name



69
70
71
72
73
74
# 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_engineRoby::ExecutionEngine

Returns the #plan‘s engine.

Returns:



44
# File 'lib/roby/interface/command_library.rb', line 44

def execution_engine; plan.execution_engine end

#planRoby::Plan

Returns the #app‘s plan.

Returns:



42
# File 'lib/roby/interface/command_library.rb', line 42

def plan; app.plan end

#subcommand(name, interface, description) ⇒ Object

Declare a subcommand on this interface

Unless with subcommand, the interface must already be instanciated



62
63
64
# File 'lib/roby/interface/command_library.rb', line 62

def subcommand(name, interface, description)
    subcommands[name] = [interface, description]
end