Merge pull request #278 from dlanileonardo/master

Auto parse options from file .github_changelog_generator
This commit is contained in:
Petr Korolev
2015-09-17 11:58:29 +03:00
8 changed files with 86 additions and 1 deletions
+3 -1
View File
@@ -9,8 +9,10 @@ module GitHubChangelogGenerator
def self.parse_options
options = get_default_options
parser = setup_parser(options)
parser_file = ParserFile.new options
parser_file.parse!
parser = setup_parser(options)
parser.parse!
if options[:user].nil? || options[:project].nil?
@@ -0,0 +1,36 @@
module GitHubChangelogGenerator
class ParserFile
def initialize(options)
@options = options
end
def file
File.expand_path(@options[:params_file] || ".github_changelog_generator")
end
def file?
File.exist?(file)
end
def file_open
File.open(file)
end
def parse!
return unless file?
file_open.each do |line|
begin
key, value = line.split("=")
key_sym = key.sub("-", "_").to_sym
value = value.gsub(/[\n\r]+/, "")
value = true if value =~ (/^(true|t|yes|y|1)$/i)
value = false if value =~ (/^(false|f|no|n|0)$/i)
@options[key_sym] = value
rescue
raise "File #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
end
end
@options
end
end
end