Skip to content

Commit

Permalink
fluent-plugin-config-format: use markdown table
Browse files Browse the repository at this point in the history
You can see list of parameters at a glance with --compact option

Before:

  * name (type) (required?) description

  * Available values: ...

  * Default value: ...

  * Alias:

  * Deprecated:

  * Obsoleted:

After:

  ### Configuration

  |parameter|type|description|default|
  |---|---|---|---|
  |...|...|...|...|
  • Loading branch information
kenhys committed Feb 2, 2021
1 parent 2718d79 commit 17be874
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def dump_section_markdown(base_section, level = 0)
else
sections, params = base_section.partition {|_name, value| value[:section] }
end
if @compact 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"
Expand Down
17 changes: 1 addition & 16 deletions templates/plugin_config_formatter/param.md-compact.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,4 @@ deprecated = config[:deprecated]
obsoleted = config[:obsoleted]
description = config[:desc]
-%>
* **<%= name %>** (<%= type %>) (<%= required_label %>): <%= description %>
<%- if type == :enum -%>
* Available values: <%= config[:list].join(", ") %>
<%- end -%>
<%- if default -%>
* Default value: `<%= default %>`.
<%- end -%>
<%- if alias_name -%>
* Alias: <%= alias_name %>
<%- end -%>
<%- if deprecated -%>
* Deprecated: <%= deprecated %>
<%- end -%>
<%- if obsoleted -%>
* Obsoleted: <%= :obsoleted %>
<%- end -%>
|<%= name %>|<%= type %> (<%= required_label %>)|<%= description %><%- if type == :enum -%> (<%= config[:list].map{|x| "`#{x}`"}.join(", ") %>)<%- end -%><%- if alias_name -%><br>Alias: <%= alias_name %><%- end -%><%- if deprecated -%><br>Deprecated: <%= deprecated %><%- end -%><%- if obsoleted -%><br>Obsoleted: <%= :obsoleted %><%- end -%>|<%- if default -%>`<%= default %>`<%- end -%>|
67 changes: 67 additions & 0 deletions test/command/test_plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,30 @@ class SimpleServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
path to something
TEXT
assert_equal(expected, dumped_config)
end

test "input simple (compact)" do
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", "--compact", "input", "simple"]).call
end
expected = <<TEXT
## Plugin helpers
* [inject](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-inject)
* [compat_parameters](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-compat_parameters)
* See also: [Input Plugin Overview](https://docs.fluentd.org/v/1.0/input#overview)
## TestFluentPluginConfigFormatter::SimpleInput
### Configuration
|parameter|type|description|default|
|---|---|---|---|
|path|string (required)|path to something||
TEXT
assert_equal(expected, dumped_config)
end
Expand Down Expand Up @@ -298,6 +322,49 @@ class SimpleServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
TEXT
assert_equal(expected, dumped_config)
end

test "output complex (compact)" do
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", "--compact", "output", "complex"]).call
end
expected = <<TEXT
## Plugin helpers
* [inject](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-inject)
* [compat_parameters](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-compat_parameters)
* See also: [Output Plugin Overview](https://docs.fluentd.org/v/1.0/output#overview)
## TestFluentPluginConfigFormatter::ComplexOutput
### \\<authentication\\> section (required) (single)
### Configuration
|parameter|type|description|default|
|---|---|---|---|
|username|string (required)|username||
|password|string (required)|password||
### \\<parent\\> section (optional) (multiple)
#### \\<child\\> 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
Expand Down

0 comments on commit 17be874

Please sign in to comment.