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
|