Class: Bolt::Outputter::JSON
Instance Method Summary
collapse
-
#fatal_error(err) ⇒ Object
-
#handle_event(event) ⇒ Object
-
#initialize(color, verbose, trace, spin, stream = $stdout) ⇒ JSON
constructor
-
#print_action_step(step) ⇒ Object
(also: #print_action_error)
-
#print_apply_result(apply_result) ⇒ Object
-
#print_groups(count:, groups:, **_kwargs) ⇒ Object
Print inventory group information.
-
#print_guide(**kwargs) ⇒ Object
Print the guide for the specified topic.
-
#print_head ⇒ Object
-
#print_message(message) ⇒ Object
(also: #print_error)
-
#print_new_plan(**kwargs) ⇒ Object
-
#print_new_policy(**kwargs) ⇒ Object
-
#print_plan_info(plan) ⇒ Object
-
#print_plan_lookup(value) ⇒ Object
-
#print_plan_result(result) ⇒ Object
-
#print_plans(**kwargs) ⇒ Object
-
#print_plugin_list(plugins:, modulepath:) ⇒ Object
-
#print_policy_list(**kwargs) ⇒ Object
-
#print_puppetfile_result(success, puppetfile, moduledir) ⇒ Object
-
#print_result(result) ⇒ Object
-
#print_result_set(result_set) ⇒ Object
-
#print_summary(results, elapsed_time) ⇒ Object
-
#print_table(results) ⇒ Object
(also: #print_module_list, #print_module_info)
-
#print_target_info(adhoc:, inventory:, targets:, count:, **_kwargs) ⇒ Object
Print target names and where they came from.
-
#print_targets(adhoc:, inventory:, targets:, count:, **_kwargs) ⇒ Object
Print target names and where they came from.
-
#print_task_info(task:) ⇒ Object
Print information about a task.
-
#print_tasks(**kwargs) ⇒ Object
-
#print_topics(**kwargs) ⇒ Object
Print available guide topics.
for_format, #indent, #spin, #start_spin, #stop_spin
Constructor Details
#initialize(color, verbose, trace, spin, stream = $stdout) ⇒ JSON
Returns a new instance of JSON.
6
7
8
9
10
11
|
# File 'lib/bolt/outputter/json.rb', line 6
def initialize(color, verbose, trace, spin, stream = $stdout)
super
@items_open = false
@object_open = false
@preceding_item = false
end
|
Instance Method Details
#fatal_error(err) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/bolt/outputter/json.rb', line 180
def fatal_error(err)
@stream.puts "],\n" if @items_open
@stream.puts '"_error": ' if @object_open
err_obj = err.to_h
if @trace && err.backtrace
err_obj[:details] ||= {}
err_obj[:details][:backtrace] = err.backtrace
end
@stream.puts err_obj.to_json
@stream.puts '}' if @object_open
end
|
#handle_event(event) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/bolt/outputter/json.rb', line 20
def handle_event(event)
case event[:type]
when :node_result
print_result(event[:result])
when :message
print_message(event[:message])
when :verbose
print_message(event[:message]) if @verbose
end
end
|
#print_action_step(step) ⇒ Object
Also known as:
print_action_error
197
198
199
|
# File 'lib/bolt/outputter/json.rb', line 197
def print_action_step(step)
$stderr.puts(step)
end
|
#print_apply_result(apply_result) ⇒ Object
106
107
108
|
# File 'lib/bolt/outputter/json.rb', line 106
def print_apply_result(apply_result)
@stream.puts apply_result.to_json
end
|
#print_groups(count:, groups:, **_kwargs) ⇒ Object
Print inventory group information.
176
177
178
|
# File 'lib/bolt/outputter/json.rb', line 176
def print_groups(count:, groups:, **_kwargs)
@stream.puts({ count: count, groups: groups }.to_json)
end
|
#print_guide(**kwargs) ⇒ Object
Print the guide for the specified topic.
132
133
134
|
# File 'lib/bolt/outputter/json.rb', line 132
def print_guide(**kwargs)
@stream.puts(kwargs.to_json)
end
|
#print_head ⇒ Object
13
14
15
16
17
18
|
# File 'lib/bolt/outputter/json.rb', line 13
def print_head
@stream.puts '{ "items": ['
@preceding_item = false
@items_open = true
@object_open = true
end
|
#print_message(message) ⇒ Object
Also known as:
print_error
192
193
194
|
# File 'lib/bolt/outputter/json.rb', line 192
def print_message(message)
$stderr.puts(message)
end
|
#print_new_plan(**kwargs) ⇒ Object
98
99
100
|
# File 'lib/bolt/outputter/json.rb', line 98
def print_new_plan(**kwargs)
print_table(**kwargs)
end
|
#print_new_policy(**kwargs) ⇒ Object
102
103
104
|
# File 'lib/bolt/outputter/json.rb', line 102
def print_new_policy(**kwargs)
print_table(**kwargs)
end
|
#print_plan_info(plan) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/bolt/outputter/json.rb', line 80
def print_plan_info(plan)
path = plan.delete('module')
plan['module_dir'] = if path.start_with?(Bolt::Config::Modulepath::MODULES_PATH)
"built-in module"
else
path
end
@stream.puts plan.to_json
end
|
#print_plan_lookup(value) ⇒ Object
136
137
138
|
# File 'lib/bolt/outputter/json.rb', line 136
def print_plan_lookup(value)
@stream.puts(value.to_json)
end
|
#print_plan_result(result) ⇒ Object
110
111
112
113
|
# File 'lib/bolt/outputter/json.rb', line 110
def print_plan_result(result)
@stream.puts result.to_json
end
|
#print_plans(**kwargs) ⇒ Object
94
95
96
|
# File 'lib/bolt/outputter/json.rb', line 94
def print_plans(**kwargs)
print_table(**kwargs)
end
|
#print_plugin_list(plugins:, modulepath:) ⇒ Object
75
76
77
78
|
# File 'lib/bolt/outputter/json.rb', line 75
def print_plugin_list(plugins:, modulepath:)
plugins.delete(:validate_resolve_reference)
print_table('plugins' => plugins, 'modulepath' => modulepath)
end
|
#print_policy_list(**kwargs) ⇒ Object
90
91
92
|
# File 'lib/bolt/outputter/json.rb', line 90
def print_policy_list(**kwargs)
print_table(**kwargs)
end
|
#print_puppetfile_result(success, puppetfile, moduledir) ⇒ Object
140
141
142
143
144
|
# File 'lib/bolt/outputter/json.rb', line 140
def print_puppetfile_result(success, puppetfile, moduledir)
@stream.puts({ success: success,
puppetfile: puppetfile,
moduledir: moduledir.to_s }.to_json)
end
|
#print_result(result) ⇒ Object
31
32
33
34
35
|
# File 'lib/bolt/outputter/json.rb', line 31
def print_result(result)
@stream.puts ',' if @preceding_item
@stream.puts result.to_json
@preceding_item = true
end
|
#print_result_set(result_set) ⇒ Object
115
116
117
|
# File 'lib/bolt/outputter/json.rb', line 115
def print_result_set(result_set)
@stream.puts result_set.to_json
end
|
#print_summary(results, elapsed_time) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/bolt/outputter/json.rb', line 37
def print_summary(results, elapsed_time)
@stream.puts "],\n"
@preceding_item = false
@items_open = false
@stream.puts format('"target_count": %<size>d, "elapsed_time": %<elapsed>d }',
size: results.size,
elapsed: elapsed_time)
end
|
#print_table(results) ⇒ Object
Also known as:
print_module_list, print_module_info
46
47
48
|
# File 'lib/bolt/outputter/json.rb', line 46
def print_table(results)
@stream.puts results.to_json
end
|
#print_target_info(adhoc:, inventory:, targets:, count:, **_kwargs) ⇒ Object
Print target names and where they came from.
167
168
169
|
# File 'lib/bolt/outputter/json.rb', line 167
def print_target_info(adhoc:, inventory:, targets:, count:, **_kwargs)
@stream.puts({ adhoc: adhoc, inventory: inventory, targets: targets, count: count }.to_json)
end
|
#print_targets(adhoc:, inventory:, targets:, count:, **_kwargs) ⇒ Object
Print target names and where they came from.
153
154
155
156
157
158
|
# File 'lib/bolt/outputter/json.rb', line 153
def print_targets(adhoc:, inventory:, targets:, count:, **_kwargs)
adhoc[:targets] = adhoc[:targets].map { |t| t['name'] }
inventory[:targets] = inventory[:targets].map { |t| t['name'] }
targets = targets.map { |t| t['name'] }
@stream.puts({ adhoc: adhoc, inventory: inventory, targets: targets, count: count }.to_json)
end
|
#print_task_info(task:) ⇒ Object
Print information about a task.
56
57
58
59
60
61
62
63
64
|
# File 'lib/bolt/outputter/json.rb', line 56
def print_task_info(task:)
path = task.files.first['path'].chomp("/tasks/#{task.files.first['name']}")
module_dir = if path.start_with?(Bolt::Config::Modulepath::MODULES_PATH)
"built-in module"
else
path
end
@stream.puts task.to_h.merge(module_dir: module_dir).to_json
end
|
#print_tasks(**kwargs) ⇒ Object
71
72
73
|
# File 'lib/bolt/outputter/json.rb', line 71
def print_tasks(**kwargs)
print_table(**kwargs)
end
|
#print_topics(**kwargs) ⇒ Object
Print available guide topics.
123
124
125
|
# File 'lib/bolt/outputter/json.rb', line 123
def print_topics(**kwargs)
print_table(kwargs)
end
|