Parse options file options
- this proof-of-concept code duplicates OptionParser information to get something going - take care to respect the type of each option from the OptionParser
This commit is contained in:
parent
42b3955c06
commit
44bbd9ca01
|
@ -23,9 +23,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
def parse_line!(line)
|
def parse_line!(line)
|
||||||
key_sym, value = extract_pair(line)
|
key_sym, value = extract_pair(line)
|
||||||
value = true if value =~ /^(true|t|yes|y|1)$/i
|
@options[key_sym] = convert_value(value, key_sym)
|
||||||
value = false if value =~ /^(false|f|no|n|0)$/i
|
|
||||||
@options[key_sym] = value
|
|
||||||
rescue
|
rescue
|
||||||
raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
||||||
end
|
end
|
||||||
|
@ -38,5 +36,23 @@ module GitHubChangelogGenerator
|
||||||
key, value = line.split("=", 2)
|
key, value = line.split("=", 2)
|
||||||
[key.sub("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
|
[key.sub("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
KNOWN_ARRAY_KEYS = [:exclude_labels, :include_labels, :bug_labels,
|
||||||
|
:enhancement_labels, :between_tags, :exclude_tags]
|
||||||
|
KNOWN_INTEGER_KEYS = [:max_issues]
|
||||||
|
|
||||||
|
def convert_value(value, key_sym)
|
||||||
|
if KNOWN_ARRAY_KEYS.include?(key_sym)
|
||||||
|
value.split(",")
|
||||||
|
elsif KNOWN_INTEGER_KEYS.include?(key_sym)
|
||||||
|
value.to_i
|
||||||
|
elsif value =~ /^(true|t|yes|y|1)$/i
|
||||||
|
true
|
||||||
|
elsif value =~ /^(false|f|no|n|0)$/i
|
||||||
|
false
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,6 @@ describe GitHubChangelogGenerator::ParserFile do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
it "reads exclude_labels into an Array" do
|
it "reads exclude_labels into an Array" do
|
||||||
pending("Related with Bug #327.")
|
|
||||||
expect { parse.parse! }.to change { options[:exclude_labels] }
|
expect { parse.parse! }.to change { options[:exclude_labels] }
|
||||||
.from(nil)
|
.from(nil)
|
||||||
.to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"])
|
.to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user