Skip to content

Commit 464793c

Browse files
committed
(PDOC-184) revised cli
`puppet generate` behavior remains unchanged `puppet generate --format markdown` now defaults to writing to REFERENCE.md and will accept an override from --out `puppet generate --format json` defaults to printing to stdout but will accept the --out param
1 parent 4ea43e0 commit 464793c

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/puppet-strings.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {})
3131

3232
file = nil
3333
if options[:json] || options[:markdown]
34-
file = options[:path]
34+
file = if options[:json]
35+
options[:path]
36+
elsif options[:markdown]
37+
options[:path] || "REFERENCE.md"
38+
end
3539
# Disable output and prevent stats/progress when writing to STDOUT
3640
args << '-n'
3741
args << '-q' unless file

lib/puppet-strings/markdown.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ def self.generate
2121
final
2222
end
2323

24+
# mimicks the behavior of the json render, although path will never be nil
25+
# @param [String] path path to destination file
2426
def self.render(path = nil)
2527
if path.nil?
2628
puts generate
2729
exit
2830
else
2931
File.open(path, 'w') { |file| file.write(generate) }
32+
YARD::Logger.instance.debug "Wrote markdown to #{path}"
3033
end
3134
end
3235
end

lib/puppet/face/strings.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ def build_generate_options(options = nil, *yard_args)
110110
generate_options[:markup] = markup if markup
111111
generate_options[:path] = options[:out] if options[:out]
112112
generate_options[:stdout] = options[:stdout]
113-
format = options[:format] || ""
114-
if format.casecmp('markdown').zero?
115-
generate_options[:markdown] = true
116-
elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
117-
generate_options[:json] = true
113+
format = options[:format]
114+
if format
115+
if format.casecmp('markdown').zero?
116+
generate_options[:markdown] = true
117+
elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
118+
generate_options[:json] = true
119+
else
120+
raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
121+
end
118122
end
119123
end
120124
generate_options

0 commit comments

Comments
 (0)