Skip to content

Commit e18217b

Browse files
authored
Merge pull request #162 from ekohl/fix-emit-output
(PDOC-224) Handle --emit-json(-stdout) again
2 parents 47e5741 + 9728d10 commit e18217b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/puppet/face/strings.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ def build_generate_options(options = nil, *yard_args)
116116
generate_options[:markdown] = true
117117
elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
118118
generate_options[:json] = true
119+
generate_options[:path] ||= options[:emit_json] if options[:emit_json]
119120
else
120121
raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
121122
end
123+
elsif options[:emit_json] || options[:emit_json_stdout]
124+
generate_options[:json] = true
125+
generate_options[:path] ||= options[:emit_json] if options[:emit_json]
122126
end
123127
end
124128
generate_options

spec/acceptance/emit_json_options.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,20 @@
5252
output = read_file_on(master, tmpfile)
5353
expect(JSON.parse(output)).to eq(expected)
5454
end
55+
56+
it 'should emit JSON to stdout when using --emit-json-stdout' do
57+
test_module_path = get_test_module_path(master, /Module test/)
58+
on master, puppet('strings', 'generate', '--emit-json-stdout', "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") do
59+
output = stdout.chomp
60+
expect(JSON.parse(output)).to eq(expected)
61+
end
62+
end
63+
64+
it 'should write JSON to a file when using --emit-json' do
65+
test_module_path = get_test_module_path(master, /Module test/)
66+
tmpfile = master.tmpfile('json_output.json')
67+
on master, puppet('strings', 'generate', '--emit-json', tmpfile, "#{test_module_path}/lib/puppet/parser/functions/function3x.rb")
68+
output = read_file_on(master, tmpfile)
69+
expect(JSON.parse(output)).to eq(expected)
70+
end
5571
end

0 commit comments

Comments
 (0)