From 26050a2f87ba5f89231531345c6178873843a601 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Thu, 5 Jan 2023 13:40:52 +0900 Subject: [PATCH] Added config option to allow configuration files to be specified later --- lib/youplot/parser.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/youplot/parser.rb b/lib/youplot/parser.rb index 686b868..6232a01 100644 --- a/lib/youplot/parser.rb +++ b/lib/youplot/parser.rb @@ -29,12 +29,10 @@ module YouPlot ) @params = Parameters.new - - apply_config_file end def apply_config_file - return unless find_config_file + return if !config_file && find_config_file.nil? read_config_file configure @@ -79,9 +77,9 @@ module YouPlot config.each do |k, v| k = k.to_sym if option_members.include?(k) - @options[k] = v + @options[k] ||= v elsif param_members.include?(k) - @params[k] = v + @params[k] ||= v else raise Error, "Unknown option/param: #{k}" end @@ -162,6 +160,9 @@ module YouPlot puts parser.help exit if YouPlot.run_as_executable? end + parser.on('--config FILE', 'specify a config file') do |v| + @config_file = v + end parser.on('--debug', TrueClass, 'print preprocessed data') do |v| options[:debug] = v end @@ -394,6 +395,8 @@ module YouPlot warn "uplot: #{e.message}" exit 1 if YouPlot.run_as_executable? end + + apply_config_file end end end