(PDOC-184) block pointless output and re-add options
This makes sure the markdown doesn't include section headers that have no content. e.g. '## Classes' does not get put in if there are no classes. Also, we should deprecate --emit-json and --emit-json-stdout instead of just killing them.
This commit is contained in:
parent
1374b67da0
commit
7c06ed77c4
|
@ -29,6 +29,7 @@ module PuppetStrings
|
||||||
args << '--backtrace' if options[:backtrace]
|
args << '--backtrace' if options[:backtrace]
|
||||||
args << "-m#{options[:markup] || 'markdown'}"
|
args << "-m#{options[:markup] || 'markdown'}"
|
||||||
|
|
||||||
|
file = nil
|
||||||
if options[:json] || options[:markdown]
|
if options[:json] || options[:markdown]
|
||||||
file = options[:path]
|
file = options[:path]
|
||||||
# Disable output and prevent stats/progress when writing to STDOUT
|
# Disable output and prevent stats/progress when writing to STDOUT
|
||||||
|
@ -47,12 +48,12 @@ module PuppetStrings
|
||||||
|
|
||||||
# If outputting JSON, render the output
|
# If outputting JSON, render the output
|
||||||
if options[:json]
|
if options[:json]
|
||||||
render_json(options[:path])
|
render_json(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
# If outputting Markdown, render the output
|
# If outputting Markdown, render the output
|
||||||
if options[:markdown]
|
if options[:markdown]
|
||||||
render_markdown(options[:path])
|
render_markdown(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@ require_relative 'puppet_class'
|
||||||
|
|
||||||
module PuppetStrings::Markdown
|
module PuppetStrings::Markdown
|
||||||
module PuppetClasses
|
module PuppetClasses
|
||||||
|
|
||||||
|
# @return [Array] list of classes
|
||||||
def self.in_classes
|
def self.in_classes
|
||||||
YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
|
YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = "## Classes\n\n"
|
final = in_classes.length > 0 ? "## Classes\n\n" : ""
|
||||||
in_classes.each do |klass|
|
in_classes.each do |klass|
|
||||||
final << PuppetStrings::Markdown::PuppetClass.new(klass).render
|
final << PuppetStrings::Markdown::PuppetClass.new(klass).render
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,14 @@ require_relative 'puppet_defined_type'
|
||||||
|
|
||||||
module PuppetStrings::Markdown
|
module PuppetStrings::Markdown
|
||||||
module PuppetDefinedTypes
|
module PuppetDefinedTypes
|
||||||
|
|
||||||
|
# @return [Array] list of defined types
|
||||||
def self.in_dtypes
|
def self.in_dtypes
|
||||||
YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
|
YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = "## Defined types\n\n"
|
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
|
||||||
in_dtypes.each do |type|
|
in_dtypes.each do |type|
|
||||||
final << PuppetStrings::Markdown::PuppetDefinedType.new(type).render
|
final << PuppetStrings::Markdown::PuppetDefinedType.new(type).render
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,14 @@ require_relative 'puppet_function'
|
||||||
|
|
||||||
module PuppetStrings::Markdown
|
module PuppetStrings::Markdown
|
||||||
module PuppetFunctions
|
module PuppetFunctions
|
||||||
|
|
||||||
|
# @return [Array] list of functions
|
||||||
def self.in_functions
|
def self.in_functions
|
||||||
YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
|
YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = "## Functions\n\n"
|
final = in_functions.length > 0 ? "## Functions\n\n" : ""
|
||||||
in_functions.each do |func|
|
in_functions.each do |func|
|
||||||
final << PuppetStrings::Markdown::PuppetFunction.new(func).render
|
final << PuppetStrings::Markdown::PuppetFunction.new(func).render
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,14 @@ require_relative 'puppet_resource_type'
|
||||||
|
|
||||||
module PuppetStrings::Markdown
|
module PuppetStrings::Markdown
|
||||||
module PuppetResourceTypes
|
module PuppetResourceTypes
|
||||||
|
|
||||||
|
# @return [Array] list of resource types
|
||||||
def self.in_rtypes
|
def self.in_rtypes
|
||||||
YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
|
YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = "## Resource types\n\n"
|
final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
|
||||||
in_rtypes.each do |type|
|
in_rtypes.each do |type|
|
||||||
final << PuppetStrings::Markdown::PuppetResourceType.new(type).render
|
final << PuppetStrings::Markdown::PuppetResourceType.new(type).render
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
<% if puppet_classes -%>
|
<% if puppet_classes.length > 0 -%>
|
||||||
## Classes
|
## Classes
|
||||||
<% puppet_classes.each do |klassy| -%>
|
<% puppet_classes.each do |klassy| -%>
|
||||||
* [`<%= klassy[:name] %>`](#<%= klassy[:link] %>): <%= klassy[:desc] %>
|
* [`<%= klassy[:name] %>`](#<%= klassy[:link] %>): <%= klassy[:desc] %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_defined_types -%>
|
<% if puppet_defined_types.length > 0 -%>
|
||||||
## Defined types
|
## Defined types
|
||||||
<% puppet_defined_types.each do |dtype| -%>
|
<% puppet_defined_types.each do |dtype| -%>
|
||||||
* [`<%= dtype[:name] %>`](#<%= dtype[:link] %>): <%= dtype[:desc] %>
|
* [`<%= dtype[:name] %>`](#<%= dtype[:link] %>): <%= dtype[:desc] %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_resource_types -%>
|
<% if puppet_resource_types.length > 0 -%>
|
||||||
## Resource types
|
## Resource types
|
||||||
<% puppet_resource_types.each do |rtype| -%>
|
<% puppet_resource_types.each do |rtype| -%>
|
||||||
* [`<%= rtype[:name] %>`](#<%= rtype[:link] %>): <%= rtype[:desc] %>
|
* [`<%= rtype[:name] %>`](#<%= rtype[:link] %>): <%= rtype[:desc] %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_functions -%>
|
<% if puppet_functions.length > 0 -%>
|
||||||
## Functions
|
## Functions
|
||||||
<% puppet_functions.each do |func| -%>
|
<% puppet_functions.each do |func| -%>
|
||||||
* [`<%= func[:name] %>`](#<%= func[:link] %>): <%= func[:desc] %>
|
* [`<%= func[:name] %>`](#<%= func[:link] %>): <%= func[:desc] %>
|
||||||
|
|
|
@ -16,6 +16,12 @@ Puppet::Face.define(:strings, '0.0.1') do
|
||||||
option '--markup FORMAT' do
|
option '--markup FORMAT' do
|
||||||
summary "The markup format to use for docstring text (defaults to 'markdown')."
|
summary "The markup format to use for docstring text (defaults to 'markdown')."
|
||||||
end
|
end
|
||||||
|
option '--emit-json-stdout' do
|
||||||
|
summary 'DEPRECATED: Print JSON representation of the documentation to stdout.'
|
||||||
|
end
|
||||||
|
option '--emit-json PATH' do
|
||||||
|
summary 'DEPRECATED: Write JSON representation of the documentation to the given file.'
|
||||||
|
end
|
||||||
|
|
||||||
summary 'Generate documentation from files.'
|
summary 'Generate documentation from files.'
|
||||||
arguments '[[search_pattern] ...]'
|
arguments '[[search_pattern] ...]'
|
||||||
|
@ -94,14 +100,20 @@ Puppet::Face.define(:strings, '0.0.1') do
|
||||||
generate_options[:yard_args] = yard_args unless yard_args.empty?
|
generate_options[:yard_args] = yard_args unless yard_args.empty?
|
||||||
|
|
||||||
if options
|
if options
|
||||||
|
if options[:emit_json]
|
||||||
|
$stderr.puts "WARNING: '--emit-json PATH' is deprecated. Use '--format json --out PATH' instead."
|
||||||
|
end
|
||||||
|
if options[:emit_json_stdout]
|
||||||
|
$stderr.puts "WARNING: '--emit-json-stdout' is deprecated. Use '--format json' instead."
|
||||||
|
end
|
||||||
markup = options[:markup]
|
markup = options[:markup]
|
||||||
generate_options[:markup] = markup if markup
|
generate_options[:markup] = markup if markup
|
||||||
generate_options[:path] = options[:out] if options[:out]
|
generate_options[:path] = options[:out] if options[:out]
|
||||||
generate_options[:stdout] = options[:stdout]
|
generate_options[:stdout] = options[:stdout]
|
||||||
format = options[:format] || ""
|
format = options[:format] || ""
|
||||||
if format.casecmp 'markdown'
|
if format.casecmp('markdown') == 0
|
||||||
generate_options[:markdown] = true
|
generate_options[:markdown] = true
|
||||||
elsif format.casecmp 'json'
|
elsif format.casecmp('json') == 0 || options[:emit_json] || options[:emit_json_stdout]
|
||||||
generate_options[:json] = true
|
generate_options[:json] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue