Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fluent-plugin-config-format: use markdown table #3240

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down Expand Up @@ -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!
Expand Down
10 changes: 10 additions & 0 deletions templates/plugin_config_formatter/param.md-table.erb
Original file line number Diff line number Diff line change
@@ -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 -%><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 (table)" do
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", "--table", "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 (table)" do
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", "--table", "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