Class: MotherBrain::Cli::SubCommand::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/mb/cli/sub_command.rb

Overview

A base class that all dynamically generated SubCommands inherit from

Direct Known Subclasses

Component, Plugin

Class Method Summary collapse

Methods inherited from Base

register_subcommand, ui

Class Method Details

.define_task(command) ⇒ Object

Define a new Thor task from the given MotherBrain::Command

Parameters:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/mb/cli/sub_command.rb', line 49

def define_task(command)
  plugin_name    = command.plugin.name
  plugin_version = command.plugin.version.to_s
  component_name = nil

  if command.type == :component
    component_name = command.scope.name
  end

  environment  = CliGateway.invoked_opts[:environment]
  execute_args = command.execute.parameters.collect { |type, parameter| parameter }

  usage = command.name
  if execute_args.any?
    usage += " #{execute_args.map(&:upcase).join(' ')}"
  end

  method_option :force,
    type: :boolean,
    default: false,
    desc: "Run command even if the environment is locked",
    aliases: "-f"
  method_option :only,
    type: :array,
    default: nil,
    desc: "Run command only on the given hostnames or IPs",
    aliases: "-o"
  desc(usage, command.description)
  define_method command.name.to_sym, ->(*task_args) do
    job = command_invoker.async_invoke(command.name,
      plugin: plugin_name,
      component: component_name,
      version: plugin_version,
      environment: environment,
      arguments: task_args,
      force: options[:force],
      node_filter: options[:only]
    )

    display_job(job)
  end
end

.descriptionObject

Raises:



42
43
44
# File 'lib/mb/cli/sub_command.rb', line 42

def description
  raise AbstractFunction
end

.fabricate(*args) ⇒ Object

Raises:

  • (AbstractFunction)

    if the inheriting class does not implement this function



34
35
36
# File 'lib/mb/cli/sub_command.rb', line 34

def fabricate(*args)
  raise AbstractFunction, "Class '#{self}' must implement abstract function"
end

.usageObject



38
39
40
# File 'lib/mb/cli/sub_command.rb', line 38

def usage
  "#{name} [COMMAND]"
end