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

Remove all values from previous occurrences on self-override #1376

Closed
wants to merge 6 commits into from

Conversation

Elarnon
Copy link

@Elarnon Elarnon commented Nov 8, 2018

When an argument gets self-overriden, at most a single value[1] gets removed from the existing values list. This is incorrect when the argument has multiple values per occurrence, and makes for "funny" bugs such as --input --input a b being parsed as --input b and --input a b c --input d being parsed as --input c d.

This patch fixes the issue by keeping track of how many values were already present when we started parsing each occurrence, and removing all the values but the ones for the last occurrence when a self-override occurs.

Fixes #1374

[1]: Actually at most two values due to clap handling the overrides twice, which is a separate bug fixed in v3.

…f-override

When an argument gets self-overriden, at most a single value[1] gets
removed from the existing values list.  This is incorrect when the
argument has multiple values per occurrence, and makes for "funny" bugs
such as `--input --input a b` being parsed as `--input b` and
`--input a b c --input d` being parsed as `--input c d`.

This patch fixes the issue by keeping track of how many values were
already present when we started parsing each occurrence, and removing
all the values but the ones for the last occurrence when a self-override
occurs.

[1]: Actually at most two values due to clap handling the overrides
twice, which is a separate bug fixed in v3.
@kbknapp
Copy link
Member

kbknapp commented Nov 9, 2018

Looks like lazy_static having issues on 1.21. Could you look into this and see if we need to pin an earlier version? We can bump up from 1.21 MSRV (min supported rust ver)...but I don't want to if we don't need to.

@Elarnon
Copy link
Author

Elarnon commented Nov 9, 2018

Looks like lazy_static 1.2 requires rust 1.24.1+; 1.1 works fine though. Opened #1121 and also updated my changes to work with 1.21 (I used APIs introduced in 1.26).

@Elarnon
Copy link
Author

Elarnon commented Nov 9, 2018

Oops, wrong PR. I opened #1378, not #1121.

@Elarnon
Copy link
Author

Elarnon commented Nov 17, 2018

@kbknapp do you need anything else from me on this?

@Elarnon
Copy link
Author

Elarnon commented Dec 3, 2018

Hi @kbknapp, friendly ping on this -- what can I do to help this PR go forward? Should I port it to the v3-master branch instead?

@kbknapp
Copy link
Member

kbknapp commented Dec 3, 2018

Sorry, I've been out of it recently. I'll double check through this today after I get home from work and ping you.

I've been doing all my work on v3-master recently and tried to essentially put blinders on myself with the 2.x branch so I can actually get v3 out :)

If this PR doesn't require any additional work, and you'd like to also port it to the v3-master branch that would be appreciated.

@Elarnon
Copy link
Author

Elarnon commented Dec 3, 2018

No worries! I think this is very confusing behavior so I'd really like it to be fixed for v3 actually.

I initially intended to create a follow-up PR porting the fix to v3 but I'll make a backport PR to v2 instead. I'll port the PR to v3 tonight or tomorrow.

@Elarnon
Copy link
Author

Elarnon commented Dec 3, 2018

Ported to v3 in #1391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants