diff --git a/lib/puppet/face/strings.rb b/lib/puppet/face/strings.rb index da1c458..ab5634d 100644 --- a/lib/puppet/face/strings.rb +++ b/lib/puppet/face/strings.rb @@ -116,9 +116,13 @@ Puppet::Face.define(:strings, '0.0.1') do generate_options[:markdown] = true elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout] generate_options[:json] = true + generate_options[:path] ||= options[:emit_json] if options[:emit_json] else raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'." end + elsif options[:emit_json] || options[:emit_json_stdout] + generate_options[:json] = true + generate_options[:path] ||= options[:emit_json] if options[:emit_json] end end generate_options diff --git a/spec/acceptance/emit_json_options.rb b/spec/acceptance/emit_json_options.rb index 79c53e8..f66bce1 100644 --- a/spec/acceptance/emit_json_options.rb +++ b/spec/acceptance/emit_json_options.rb @@ -52,4 +52,20 @@ describe 'Emitting JSON' do output = read_file_on(master, tmpfile) expect(JSON.parse(output)).to eq(expected) end + + it 'should emit JSON to stdout when using --emit-json-stdout' do + test_module_path = get_test_module_path(master, /Module test/) + on master, puppet('strings', 'generate', '--emit-json-stdout', "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") do + output = stdout.chomp + expect(JSON.parse(output)).to eq(expected) + end + end + + it 'should write JSON to a file when using --emit-json' do + test_module_path = get_test_module_path(master, /Module test/) + tmpfile = master.tmpfile('json_output.json') + on master, puppet('strings', 'generate', '--emit-json', tmpfile, "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") + output = read_file_on(master, tmpfile) + expect(JSON.parse(output)).to eq(expected) + end end