mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Fix a few issues when using the logstash-docgen tools
Fixes the following issues: - Make multiline plugin definition correctly take the description See rabbit mq input or output - Use a regexp to ignore encoding comment - Use `TODO` The doc gen will now ignore some TODOs. - rules are now executed in the correct order, - make sure to ignore comment not associated with a descrition of an attributes Ref: #6692 Fixes #6714
This commit is contained in:
parent
a7c456e212
commit
63dd6d7e17
1 changed files with 41 additions and 19 deletions
|
@ -4,7 +4,10 @@ module LogStash::Docgen
|
||||||
# his ancestors, the result would be the description of the plugin and the
|
# his ancestors, the result would be the description of the plugin and the
|
||||||
# actual documentation for each of the option.
|
# actual documentation for each of the option.
|
||||||
class StaticParser
|
class StaticParser
|
||||||
COMMENTS_IGNORE = ["encoding: utf-8"]
|
COMMENTS_IGNORE = Regexp.union(
|
||||||
|
Regexp.new(/encoding: utf-8/i),
|
||||||
|
Regexp.new(/TODO:/)
|
||||||
|
)
|
||||||
|
|
||||||
VALID_CLASS_NAME = /^LogStash::(Codecs|Inputs|Filters|Outputs)::(\w+)/
|
VALID_CLASS_NAME = /^LogStash::(Codecs|Inputs|Filters|Outputs)::(\w+)/
|
||||||
COMMENT_RE = /^ *#(?: (.*)| *$)/
|
COMMENT_RE = /^ *#(?: (.*)| *$)/
|
||||||
|
@ -12,20 +15,18 @@ module LogStash::Docgen
|
||||||
ENDLINES_RE = /\r\n|\n/
|
ENDLINES_RE = /\r\n|\n/
|
||||||
CLASS_DEFINITION_RE = /^ *class\s(.*) < *(::)?LogStash::(Outputs|Filters|Inputs|Codecs)::(\w)/
|
CLASS_DEFINITION_RE = /^ *class\s(.*) < *(::)?LogStash::(Outputs|Filters|Inputs|Codecs)::(\w)/
|
||||||
NEW_CLASS_DEFINITION_RE = /^module (\w+) module (\w+) class\s(.*) < *(::)?LogStash::(Outputs|Filters|Inputs|Codecs)::(\w)/
|
NEW_CLASS_DEFINITION_RE = /^module (\w+) module (\w+) class\s(.*) < *(::)?LogStash::(Outputs|Filters|Inputs|Codecs)::(\w)/
|
||||||
NEW_CLASS_DEFINITION_RE_ML = /module LogStash\n\s+module (Inputs|Codec|Outputs|Filters)\n.+\s+class (\w+) < *(::)?LogStash::(Inputs|Outputs|Filters|Codec)::/m
|
NEW_CLASS_DEFINITION_RE_ML = /^\s*class\s(.*) < *(::)?LogStash::(Outputs|Filters|Inputs|Codecs)::(\w+)/
|
||||||
CONFIG_OPTION_RE = /^\s*((mod|base).)?config +[^=].*/
|
CONFIG_OPTION_RE = /^\s*((mod|base).)?config +[^=].*/
|
||||||
CONFIG_NAME_RE = /^ *config_name .*/
|
CONFIG_NAME_RE = /^ *config_name .*/
|
||||||
RESET_DOCUMENTATION_BUFFER_RE = /^ *(class|def|module) /
|
|
||||||
|
|
||||||
def initialize(context)
|
def initialize(context)
|
||||||
@rules = {
|
@rules = [
|
||||||
COMMENT_RE => :parse_comment,
|
[ COMMENT_RE, :parse_comment ],
|
||||||
CLASS_DEFINITION_RE => :parse_class_description,
|
[ CLASS_DEFINITION_RE, :parse_class_description ],
|
||||||
NEW_CLASS_DEFINITION_RE => :parse_new_class_description,
|
[ NEW_CLASS_DEFINITION_RE_ML, :parse_new_class_description ],
|
||||||
CONFIG_OPTION_RE => :parse_config,
|
[ CONFIG_OPTION_RE, :parse_config ],
|
||||||
CONFIG_NAME_RE => :parse_config_name,
|
[ CONFIG_NAME_RE, :parse_config_name ],
|
||||||
RESET_DOCUMENTATION_BUFFER_RE => :update_description
|
]
|
||||||
}
|
|
||||||
|
|
||||||
@context = context
|
@context = context
|
||||||
|
|
||||||
|
@ -45,18 +46,21 @@ module LogStash::Docgen
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_new_class_description(class_definition)
|
def parse_new_class_description(class_definition)
|
||||||
@context.section = class_definition[2].downcase.gsub(/s$/, '')
|
@context.section = class_definition[3].downcase.gsub(/s$/, '')
|
||||||
@context.name = "#{class_definition[1]}::#{class_definition[2]}::#{class_definition[3]}"
|
@context.name = "LogStash::#{class_definition[3]}::#{class_definition[2]}"
|
||||||
|
|
||||||
update_description
|
update_description
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is not obvious, but if the plugin define a class before the main class it can trip the buffer
|
# This is not obvious, but if the plugin define a class before the main class it can trip the buffer
|
||||||
def update_description(match = nil)
|
def update_description(match = nil)
|
||||||
|
return unless reading_header?
|
||||||
|
|
||||||
description = flush_buffer
|
description = flush_buffer
|
||||||
|
|
||||||
# can only be change by the main file
|
# can only be change by the main file
|
||||||
@context.description = description if !@context.has_description? && main?
|
@context.description = description if !@context.has_description? && main?
|
||||||
|
transition_to_reading_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_config_name(match)
|
def parse_config_name(match)
|
||||||
|
@ -81,9 +85,25 @@ module LogStash::Docgen
|
||||||
|
|
||||||
def parse(file, main = false)
|
def parse(file, main = false)
|
||||||
@main = main
|
@main = main
|
||||||
|
main ? transition_to_reading_header() : transition_to_reading_attributes()
|
||||||
|
|
||||||
reset_buffer
|
reset_buffer
|
||||||
string = read_file(file)
|
string = read_file(file)
|
||||||
extract_lines(string).each { |line| parse_line(line) }
|
extract_lines(string).each do |line|
|
||||||
|
parse_line(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def transition_to_reading_attributes
|
||||||
|
@state = :reading_attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
def transition_to_reading_header
|
||||||
|
@state = :reading_header
|
||||||
|
end
|
||||||
|
|
||||||
|
def reading_header?
|
||||||
|
@state == :reading_header
|
||||||
end
|
end
|
||||||
|
|
||||||
def main?
|
def main?
|
||||||
|
@ -91,11 +111,13 @@ module LogStash::Docgen
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_line(line)
|
def parse_line(line)
|
||||||
@rules.each do |re, action|
|
@rules.each do |rule|
|
||||||
|
re, action = rule
|
||||||
if match = re.match(line)
|
if match = re.match(line)
|
||||||
send(action, match)
|
send(action, match)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_lines(string)
|
def extract_lines(string)
|
||||||
|
@ -115,7 +137,7 @@ module LogStash::Docgen
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignore_comment?(comment)
|
def ignore_comment?(comment)
|
||||||
COMMENTS_IGNORE.include?(comment)
|
COMMENTS_IGNORE.match(comment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def comment?(line)
|
def comment?(line)
|
||||||
|
@ -149,7 +171,7 @@ module LogStash::Docgen
|
||||||
# ....
|
# ....
|
||||||
# module Inputs
|
# module Inputs
|
||||||
# ...
|
# ...
|
||||||
# class File
|
# class File # new kid on the block
|
||||||
def extract_class_name(file)
|
def extract_class_name(file)
|
||||||
content = read_file(file)
|
content = read_file(file)
|
||||||
legacy_definition = content.match(CLASS_DEFINITION_RE)
|
legacy_definition = content.match(CLASS_DEFINITION_RE)
|
||||||
|
@ -162,7 +184,7 @@ module LogStash::Docgen
|
||||||
legacy_definition[1]
|
legacy_definition[1]
|
||||||
else
|
else
|
||||||
m = content.match(NEW_CLASS_DEFINITION_RE_ML)
|
m = content.match(NEW_CLASS_DEFINITION_RE_ML)
|
||||||
"LogStash::#{m[1]}::#{m[2]}"
|
"LogStash::#{m[3]}::#{m[1]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue