Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using accept, the values from the config are not routed through the type conversions #326

Open
davetron5000 opened this issue Jul 16, 2024 · 0 comments
Labels

Comments

@davetron5000
Copy link
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant