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

Long form switch/flag names don't work in config files #242

Closed
peter-ellis opened this issue May 9, 2016 · 3 comments
Closed

Long form switch/flag names don't work in config files #242

peter-ellis opened this issue May 9, 2016 · 3 comments
Labels

Comments

@peter-ellis
Copy link

When a switch or flag has both a short form (e.g, -a) and a long form (e.g., --annotate) option name, only the short form appears to work when used in the config file; the long form is ignored. When there is only a long form, it works okay in the config file.

It seems like either short or long form names should work in the config file. If anything, maybe there should be a preference for long form names for the sake of readability.

I think I tracked the problem down to the override_default method in AppSupport. The issue is that the token 'name' is just the short form name when both short and long exist.

I have a fix that seems to work for me, but is not maybe pull request worthy. So here it is for your consideration:

def override_default(tokens, config)
  tokens.each do |name, token|
    all_aliases = [token.name]
    all_aliases += token.aliases if (token.aliases)
    matches = config.keys & all_aliases  # Could have multiple aliases in config file, i.e., over specified
    if not matches.empty?
      token.default_value = config[matches.last]  # Use last match; should be last occurrence in config file, but not necessarily
    end
  end
end
@pboling
Copy link

pboling commented May 9, 2016

This would have been very confusing for me, and I was about to run headlong into it. Thanks for the report! 👍

@davetron5000
Copy link
Owner

Yeah, the intention is for either to work. At one point there was a bug where initconfig would write both (or all) versions of a flag into the config file, thus making it appear to work with tests.

There are a few tests for this:

They use this test config: https://github.com/davetron5000/gli/blob/gli-2/test/config.yaml

Is that enough for you to write a failing test? That would be super helpful is sorting this out.

@davetron5000
Copy link
Owner

Consolidated into #305

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

3 participants