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.
8
9
10
11
12
13
|
# File 'lib/bolt/outputter/json.rb', line 8
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
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/bolt/outputter/json.rb', line 182
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
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/bolt/outputter/json.rb', line 22
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
199
200
201
|
# File 'lib/bolt/outputter/json.rb', line 199
def print_action_step(step)
$stderr.puts(step)
end
|
#print_apply_result(apply_result) ⇒ Object
108
109
110
|
# File 'lib/bolt/outputter/json.rb', line 108
def print_apply_result(apply_result)
@stream.puts apply_result.to_json
end
|
#print_groups(count:, groups:, **_kwargs) ⇒ Object
Print inventory group information.
178
179
180
|
# File 'lib/bolt/outputter/json.rb', line 178
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.
134
135
136
|
# File 'lib/bolt/outputter/json.rb', line 134
def print_guide(**kwargs)
@stream.puts(kwargs.to_json)
end
|
#print_head ⇒ Object
15
16
17
18
19
20
|
# File 'lib/bolt/outputter/json.rb', line 15
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
194
195
196
|
# File 'lib/bolt/outputter/json.rb', line 194
def print_message(message)
$stderr.puts(Bolt::Util::Format.stringify(message))
end
|
#print_new_plan(**kwargs) ⇒ Object
100
101
102
|
# File 'lib/bolt/outputter/json.rb', line 100
def print_new_plan(**kwargs)
print_table(**kwargs)
end
|
#print_new_policy(**kwargs) ⇒ Object
104
105
106
|
# File 'lib/bolt/outputter/json.rb', line 104
def print_new_policy(**kwargs)
print_table(**kwargs)
end
|
#print_plan_info(plan) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/bolt/outputter/json.rb', line 82
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
138
139
140
|
# File 'lib/bolt/outputter/json.rb', line 138
def print_plan_lookup(value)
@stream.puts(value.to_json)
end
|
#print_plan_result(result) ⇒ Object
112
113
114
115
|
# File 'lib/bolt/outputter/json.rb', line 112
def print_plan_result(result)
@stream.puts result.to_json
end
|
#print_plans(**kwargs) ⇒ Object
96
97
98
|
# File 'lib/bolt/outputter/json.rb', line 96
def print_plans(**kwargs)
print_table(**kwargs)
end
|
#print_plugin_list(plugins:, modulepath:) ⇒ Object
77
78
79
80
|
# File 'lib/bolt/outputter/json.rb', line 77
def print_plugin_list(plugins:, modulepath:)
plugins.delete(:validate_resolve_reference)
print_table('plugins' => plugins, 'modulepath' => modulepath)
end
|
#print_policy_list(**kwargs) ⇒ Object
92
93
94
|
# File 'lib/bolt/outputter/json.rb', line 92
def print_policy_list(**kwargs)
print_table(**kwargs)
end
|
#print_puppetfile_result(success, puppetfile, moduledir) ⇒ Object
142
143
144
145
146
|
# File 'lib/bolt/outputter/json.rb', line 142
def print_puppetfile_result(success, puppetfile, moduledir)
@stream.puts({ success: success,
puppetfile: puppetfile,
moduledir: moduledir.to_s }.to_json)
end
|
#print_result(result) ⇒ Object
33
34
35
36
37
|
# File 'lib/bolt/outputter/json.rb', line 33
def print_result(result)
@stream.puts ',' if @preceding_item
@stream.puts result.to_json
@preceding_item = true
end
|
#print_result_set(result_set) ⇒ Object
117
118
119
|
# File 'lib/bolt/outputter/json.rb', line 117
def print_result_set(result_set)
@stream.puts result_set.to_json
end
|
#print_summary(results, elapsed_time) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/bolt/outputter/json.rb', line 39
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
48
49
50
|
# File 'lib/bolt/outputter/json.rb', line 48
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.
169
170
171
|
# File 'lib/bolt/outputter/json.rb', line 169
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.
155
156
157
158
159
160
|
# File 'lib/bolt/outputter/json.rb', line 155
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.
58
59
60
61
62
63
64
65
66
|
# File 'lib/bolt/outputter/json.rb', line 58
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
73
74
75
|
# File 'lib/bolt/outputter/json.rb', line 73
def print_tasks(**kwargs)
print_table(**kwargs)
end
|
#print_topics(**kwargs) ⇒ Object
Print available guide topics.
125
126
127
|
# File 'lib/bolt/outputter/json.rb', line 125
def print_topics(**kwargs)
print_table(kwargs)
end
|