Skip to content

Commit 8f22f15

Browse files
committed
Fix config info lookup
1 parent 29bb6d5 commit 8f22f15

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lib/youplot/parser.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def show_main_help(out = $stdout)
228228
end
229229

230230
def show_config_info
231+
ensure_config_loaded
232+
231233
if @config_file
232234
puts "config file : #{@config_file}"
233235
puts config.inspect
@@ -245,6 +247,15 @@ def show_config_info
245247
exit if YouPlot.run_as_executable?
246248
end
247249

250+
def ensure_config_loaded
251+
apply_config_file unless config
252+
rescue StandardError => e
253+
raise unless YouPlot.run_as_executable?
254+
255+
warn "YouPlot: #{e.message}"
256+
exit 1
257+
end
258+
248259
def sub_parser_add_symbol
249260
sub_parser.on_head('--symbol STR', String, 'character to be used to plot the bars') do |v|
250261
params.symbol = v

‎test/youplot/parser_test.rb‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ def with_stdout(stdout)
9797
end
9898
end
9999

100+
test :show_config_info_finds_default_config_file do
101+
Dir.mktmpdir do |dir|
102+
Dir.chdir(dir) do
103+
File.write('.youplot.yml', "width: 42\n")
104+
105+
parser = YouPlot::Parser.new
106+
output = capture_stdout do
107+
parser.show_config_info
108+
end
109+
110+
assert_include output, 'config file : '
111+
assert_include output, '.youplot.yml'
112+
assert_match(/"width"\s*=>\s*42/, output)
113+
end
114+
end
115+
end
116+
100117
test :config_hyphen_output_uses_stdout do
101118
stdout = StringIO.new
102119

0 commit comments

Comments
 (0)