Skip to content

Commit 1316975

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 1316975

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ For details about Strings JSON output, see [Strings JSON schema](https://github.
177177

178178
Strings can also produce documentation in Markdown and then either generate an `.md` file or print Markdown to stdout. The generated markdown layout has been reviewed and approved by Puppet's tech pubs team and is the same that is used in Puppet Supported modules.
179179

180-
To generate Markdown documentation to a file, run:
180+
To generate REFERENCE.md:
181181

182182
```
183-
$ puppet strings generate --format markdown --out REFERENCE.md
183+
$ puppet strings generate --format markdown
184184
```
185185

186-
To generate and then print Markdown documentation to stdout, run:
186+
To write Markdown documentation to another file, use the --out option:
187187

188188
```
189-
$ puppet strings generate --format markdown
189+
$ puppet strings generate --format markdown --out docs/INFO.md
190190
```
191191

192192
### Output documents to GitHub Pages
@@ -301,7 +301,7 @@ end
301301

302302
All provider method calls, including `confine`, `defaultfor`, and `commands`, are automatically parsed and documented by Strings. The `desc` method is used to generate the docstring, and can include tags such as `@example` if written as a heredoc.
303303

304-
Document types that use the new [Resource API](https://github.com/puppetlabs/puppet-resource_api).
304+
Document types that use the new [Resource API](https://github.com/puppetlabs/puppet-resource_api):
305305

306306
```ruby
307307
Puppet::ResourceApi.register_type(

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)