Skip to content
New issue

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

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

Already on GitHub? # to your account

Passing a Switch key is ignored if the Switch contains a flag #95

Closed
natanrolnik opened this issue Feb 2, 2017 · 1 comment
Closed

Comments

@natanrolnik
Copy link
Contributor

natanrolnik commented Feb 2, 2017

Imagine the following scenario:

Switch(flag: "f", key: "force", usage: "Whether to force")

Surprisingly, calling my-tool do something -f has a different than my-tool do something --force. The former one works, while the latter fails.

However, if the switch is initialized with: Switch(flag: nil, key: "force", usage: "Whether to force"), without a flag, --force works.

This is due to a (what I understand as a) bug in the Switch <| function:

case let .arguments(arguments):
    var enabled = arguments.consume(key: option.key)

    if let flag = option.flag {
        enabled = arguments.consumeBoolean(flag: flag)
    }
    return .success(enabled)

You can see that, when a flag exists, it will always read try to read if the flag was passed, and this will override the value if the key was passed.

I've opened a PR with tests and the fix for them.

@mdiep
Copy link
Member

mdiep commented Feb 3, 2017

Fixed by #96.

@mdiep mdiep closed this as completed Feb 3, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants