-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Labels
Description
Because GLI is using OptionParser
(from the stdlib) to do type conversions, they only happen when arguments are parsed from the command line. When arguments are parsed from the config file, they will not be type-checked.
This is a bug, but also points to the sorta bad design of the configuration system.
The following test shows the bug (copied from #190):
# test/unit/support/gli_test_config.yml
# last line is the addition to show the behavior
---
commands:
:command:
:g: bar
:s: true
:other_command:
:g: foobar
:f: barfoo
:f: foo
:bleorgh: true
:t: false
:arr: foo,bar
# test/unit/gli_test.rb
def test_init_from_config_with_accept
failure = nil
@app.reset
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml'))
@app.accept(Array) do |value|
value.split(/,/).map(&:strip)
end
called = false
@app.flag :arr, :accept => Array
@app.flag :work, :accept => Array
@app.command :command do |c|
c.action do |g,o,a|
begin
called = true
assert_equal ['foo','bar'], g[:arr]
assert_equal ['bar','foo'], g[:work]
rescue Exception => ex
failure = ex
end
end
end
@app.run(['--work bar,foo command'])
assert called
raise failure if !failure.nil?
end