Skip to content

Commit 1a9c299

Browse files
committed
Add options for failing resource check on command line
1 parent bd929dd commit 1a9c299

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/puppet/application/resource.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def preinit
1515
option("--verbose", "-v")
1616
option("--edit", "-e")
1717
option("--to_yaml", "-y")
18+
option('--fail-when-not-found', '-f')
1819

1920
option("--types", "-t") do |_arg|
2021
env = Puppet.lookup(:environments).get(Puppet[:environment]) || create_default_environment
@@ -109,6 +110,10 @@ def help
109110
Output found resources in yaml format, suitable to use with Hiera and
110111
create_resources.
111112
113+
* --fail-when-not-found:
114+
Fails and returns an exit code of 1 if the resource is not found, valid only
115+
for Windows and SystemD services.
116+
112117
EXAMPLE
113118
-------
114119
This example uses `puppet resource` to return a Puppet configuration for
@@ -238,7 +243,7 @@ def find_or_save_resources(type, name, params)
238243
# save returns [resource that was saved, transaction log from applying the resource]
239244
save_result, report = Puppet::Resource.indirection.save(resource, key)
240245
status = report.resource_statuses[resource.ref]
241-
raise "Failed to manage resource #{resource.ref}" if status&.failed?
246+
raise "Failed to manage resource #{resource.ref}" if status&.failed? && !options[:fail_when_not_found].nil? && options[:fail_when_not_found]
242247

243248
[save_result]
244249
end

0 commit comments

Comments
 (0)