Skip to content

Commit dd0ce50

Browse files
committed
(PUP-11604) List unmet deps in --render-as json
Before this patch, running `puppet module list` would report unmet dependencies on the console, but not when running as `--render-as json`. This patch adds an `unmet_dependencies` key to the data returned by `puppet module list --render-as json`.
1 parent 13188f1 commit dd0ce50

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/puppet/face/module/list.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@
6060
when_invoked do |options|
6161
Puppet::ModuleTool.set_option_defaults(options)
6262
environment = options[:environment_instance]
63+
modules_by_path = environment.modules_by_path
6364

6465
{
6566
:environment => environment,
66-
:modules_by_path => environment.modules_by_path,
67+
:modules_by_path => modules_by_path,
68+
:unmet_dependencies => unmet_dependencies(environment),
6769
}
6870
end
6971

@@ -103,12 +105,13 @@
103105
end
104106
end
105107

106-
def warn_unmet_dependencies(environment)
108+
109+
def unmet_dependencies(environment)
107110
error_types = [:non_semantic_version, :version_mismatch, :missing]
108111

109-
@unmet_deps = {}
112+
unmet_deps = {}
110113
error_types.each do |type|
111-
@unmet_deps[type] = Hash.new do |hash, key|
114+
unmet_deps[type] = Hash.new do |hash, key|
112115
hash[key] = { :errors => [], :parent => nil }
113116
end
114117
end
@@ -130,16 +133,22 @@ def warn_unmet_dependencies(environment)
130133
parent_version = dep[:parent][:version]
131134

132135
msg = _("'%{parent_name}' (%{parent_version}) requires '%{dependency_name}' (%{dependency_version})") % { parent_name: parent_name, parent_version: parent_version, dependency_name: dep_name, dependency_version: version_constraint }
133-
@unmet_deps[type][dep[:name]][:errors] << msg
134-
@unmet_deps[type][dep[:name]][:parent] = {
136+
unmet_deps[type][dep[:name]][:errors] << msg
137+
unmet_deps[type][dep[:name]][:parent] = {
135138
:name => dep[:parent][:name],
136139
:version => parent_version
137140
}
138-
@unmet_deps[type][dep[:name]][:version] = installed_version
141+
unmet_deps[type][dep[:name]][:version] = installed_version
139142
end
140143
end
141144
end
142145
end
146+
unmet_deps
147+
end
148+
149+
150+
def warn_unmet_dependencies(environment)
151+
@unmet_deps = unmet_dependencies(environment)
143152

144153
# Display unmet dependencies by category.
145154
error_display_order = [:non_semantic_version, :version_mismatch, :missing]

0 commit comments

Comments
 (0)