class MotherBrain::Cli::SubCommand::Base
A base class that all dynamically generated SubCommands inherit from
Public Class Methods
define_task(command)
click to toggle source
Define a new Thor
task from the given {MotherBrain::Command}
@param [MB::Command] command
# 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
description()
click to toggle source
# File lib/mb/cli/sub_command.rb, line 42 def description raise AbstractFunction end
fabricate(*args)
click to toggle source
@raise [AbstractFunction] if the inheriting class does not implement this function
# File lib/mb/cli/sub_command.rb, line 34 def fabricate(*args) raise AbstractFunction, "Class '#{self}' must implement abstract function" end
usage()
click to toggle source
# File lib/mb/cli/sub_command.rb, line 38 def usage "#{name} [COMMAND]" end