Closed peter-ellis closed 3 years ago
This would have been very confusing for me, and I was about to run headlong into it. Thanks for the report! 👍
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:
test_init_from_config
https://github.com/davetron5000/gli/blob/gli-2/test/tc_gli.rb#L141test_command_line_overwrites_config
https://github.com/davetron5000/gli/blob/gli-2/test/tc_gli.rb#L175They 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.
Consolidated into #305
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: