Class: Choria::Colt::CLI::Tasks
- Inherits:
-
Thor
- Object
- Thor
- Thor
- Choria::Colt::CLI::Tasks
show all
- Defined in:
- lib/choria/colt/cli.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Thor
#_invalid_command_call, exit_on_failure?, is_thor_reserved_word?, start
Class Method Details
.define_targets_and_filters_options ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/choria/colt/cli.rb', line 12
def self.define_targets_and_filters_options
option :targets,
aliases: ['--target', '-t'],
desc: 'Identifies the targets of the command.'
option :targets_with_classes,
aliases: ['--targets-with-class', '-C'],
desc: 'Select the targets which have the specified Puppet classes.'
end
|
Instance Method Details
#run(*args) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/choria/colt/cli.rb', line 36
def run(*args)
raise Thor::Error, 'Task name is required' if args.empty?
input = (args)
raise Thor::Error, "Too many arguments: #{args}" unless args.count == 1
task_name = args.shift
targets, targets_with_classes = extract_targets_and_filters_from_options
environment = options['environment']
results = colt.run_bolt_task task_name, input: input, targets: targets, targets_with_classes: targets_with_classes, environment: environment do |result|
$stdout.puts formatter.format(result)
end
File.write 'last_run.json', JSON.pretty_generate(results)
rescue Choria::Orchestrator::Error
end
|
#show(*tasks_names) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/choria/colt/cli.rb', line 69
def show(*tasks_names)
environment = options['environment']
require 'active_support/cache/file_store'
cache = ActiveSupport::Cache::FileStore.new File.expand_path('~/.cache/colt/tasks')
tasks = colt.tasks(environment: environment, cache: cache)
if tasks_names.empty?
show_tasks_summary(tasks)
else
tasks_names.each { |task_name| show_task_details(task_name, tasks) }
end
end
|
#status(task_id) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/choria/colt/cli.rb', line 94
def status(task_id)
validate_style_option
targets, targets_with_classes = extract_targets_and_filters_from_options
case options['style']
when 'continous'
results = colt.wait_bolt_task(task_id, targets: targets, targets_with_classes: targets_with_classes) do |result|
$stdout.puts formatter.format(result)
end
when 'summary'
show_summarized_status(task_id, targets: targets, targets_with_classes: targets_with_classes)
end
File.write 'last_run.json', JSON.pretty_generate(results)
rescue Choria::Orchestrator::Error
end
|