diff --git a/lib/fluent/command/plugin_config_formatter.rb b/lib/fluent/command/plugin_config_formatter.rb
index c9bb749911..34ba22dd69 100644
--- a/lib/fluent/command/plugin_config_formatter.rb
+++ b/lib/fluent/command/plugin_config_formatter.rb
@@ -162,9 +162,20 @@ def dump_section_markdown(base_section, level = 0)
else
sections, params = base_section.partition {|_name, value| value[:section] }
end
+ if @table and not params.empty?
+ dumped << "### Configuration\n\n"
+ dumped << "|parameter|type|description|default|\n"
+ dumped << "|---|---|---|---|\n"
+ end
params.each do |name, config|
next if name == :section
- template_name = @compact ? "param.md-compact.erb" : "param.md.erb"
+ template_name = if @compact
+ "param.md-compact.erb"
+ elsif @table
+ "param.md-table.erb"
+ else
+ "param.md.erb"
+ end
template = template_path(template_name).read
dumped <<
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
@@ -257,6 +268,9 @@ def prepare_option_parser
@parser.on("-p", "--plugin=DIR", "Add plugin directory") do |s|
@plugin_dirs << s
end
+ @parser.on("-t", "--table", "Use table syntax to dump parameters") do
+ @table = true
+ end
end
def parse_options!
diff --git a/templates/plugin_config_formatter/param.md-table.erb b/templates/plugin_config_formatter/param.md-table.erb
new file mode 100644
index 0000000000..68ad5ddbaf
--- /dev/null
+++ b/templates/plugin_config_formatter/param.md-table.erb
@@ -0,0 +1,10 @@
+<%-
+type = config[:type]
+required_label = config[:required] ? "required" : "optional"
+default = config[:default]
+alias_name = config[:alias]
+deprecated = config[:deprecated]
+obsoleted = config[:obsoleted]
+description = config[:desc]
+-%>
+|<%= name %>|<%= type %> (<%= required_label %>)|<%= description %><%- if type == :enum -%> (<%= config[:list].map{|x| "`#{x}`"}.join(", ") %>)<%- end -%><%- if alias_name -%>
Alias: <%= alias_name %><%- end -%><%- if deprecated -%>
Deprecated: <%= deprecated %><%- end -%><%- if obsoleted -%>
Obsoleted: <%= :obsoleted %><%- end -%>|<%- if default -%>`<%= default %>`<%- end -%>|
diff --git a/test/command/test_plugin_config_formatter.rb b/test/command/test_plugin_config_formatter.rb
index f32b479f79..28e311401d 100644
--- a/test/command/test_plugin_config_formatter.rb
+++ b/test/command/test_plugin_config_formatter.rb
@@ -225,6 +225,30 @@ class SimpleServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
path to something
+TEXT
+ assert_equal(expected, dumped_config)
+ end
+
+ test "input simple (table)" do
+ dumped_config = capture_stdout do
+ FluentPluginConfigFormatter.new(["--format=markdown", "--table", "input", "simple"]).call
+ end
+ expected = < section (required) (single)
+
+### Configuration
+
+|parameter|type|description|default|
+|---|---|---|---|
+|username|string (required)|username||
+|password|string (required)|password||
+
+
+### \\ section (optional) (multiple)
+
+
+#### \\ section (optional) (multiple)
+
+### Configuration
+
+|parameter|type|description|default|
+|---|---|---|---|
+|names|array (required)|names||
+|difficulty|enum (optional)|difficulty (`easy`, `normal`, `hard`)|`normal`|
+
+
+
TEXT
assert_equal(expected, dumped_config)
end