class MotherBrain::Cli::SubCommand::Component

A set of component tasks collected into a SubCommand to be registered with the CliGateway. This class should not be instantiated, configured, and used by itself. Use {SubCommand::Component.fabricate} to create an anonymous class of this type.

@api private

Attributes

component[R]

Return the component associated with this instance of the class

@return [MB::Component]

Public Class Methods

fabricate(component) click to toggle source

@param [MB::Component] component

@return [SubCommand::Component]

# File lib/mb/cli/sub_command/component.rb, line 23
def fabricate(component)
  environment = CliGateway.invoked_opts[:environment]

  Class.new(self) do
    set_component(component)

    component.commands.each do |command|
      define_task(command)
    end

    desc("nodes", "List all nodes grouped by Group")
    define_method(:nodes) do
      ui.say "Listing nodes for '#{component.name}' in '#{environment}':"
      nodes = component.nodes(environment).each do |group, nodes|
        nodes.collect! { |node| "#{node.public_hostname} (#{node.public_ipv4})" }
      end
      ui.say nodes.to_yaml
    end
  end
end
set_component(component) click to toggle source

Set the component for this instance of the class and tailor the class for the given component.

@param [MB::Component] component

# File lib/mb/cli/sub_command/component.rb, line 48
def set_component(component)
  self.namespace(component.name)
  @component = component
end