Skip to content

Commit 7fc2806

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

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/puppet/application/resource.rb

Lines changed: 5 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,9 @@ 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.
115+
112116
EXAMPLE
113117
-------
114118
This example uses `puppet resource` to return a Puppet configuration for
@@ -238,7 +242,7 @@ def find_or_save_resources(type, name, params)
238242
# save returns [resource that was saved, transaction log from applying the resource]
239243
save_result, report = Puppet::Resource.indirection.save(resource, key)
240244
status = report.resource_statuses[resource.ref]
241-
raise "Failed to manage resource #{resource.ref}" if status&.failed?
245+
raise "Failed to manage resource #{resource.ref}" if status&.failed? && !options[:fail_when_not_found].nil? && options[:fail_when_not_found]
242246

243247
[save_result]
244248
end

0 commit comments

Comments
 (0)