(PDOC-224) Handle --emit-json(-stdout) again
This commit is contained in:
parent
47e57418e5
commit
9728d1004a
|
@ -116,9 +116,13 @@ Puppet::Face.define(:strings, '0.0.1') do
|
||||||
generate_options[:markdown] = true
|
generate_options[:markdown] = true
|
||||||
elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
|
elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
|
||||||
generate_options[:json] = true
|
generate_options[:json] = true
|
||||||
|
generate_options[:path] ||= options[:emit_json] if options[:emit_json]
|
||||||
else
|
else
|
||||||
raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
|
raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
generate_options
|
generate_options
|
||||||
|
|
|
@ -52,4 +52,20 @@ describe 'Emitting JSON' do
|
||||||
output = read_file_on(master, tmpfile)
|
output = read_file_on(master, tmpfile)
|
||||||
expect(JSON.parse(output)).to eq(expected)
|
expect(JSON.parse(output)).to eq(expected)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue