(PDOC-224) Handle --emit-json(-stdout) again

This commit is contained in:
Ewoud Kohl van Wijngaarden 2018-03-01 18:13:55 +01:00
parent 47e57418e5
commit 9728d1004a
No known key found for this signature in database
GPG Key ID: C6EC8F04A934BAB1
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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