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

Parser panics using global args and calling get_matches_from_safe_borrow() repeatedly #1076

Closed
tomprogrammer opened this issue Oct 24, 2017 · 5 comments

Comments

@tomprogrammer
Copy link

Rust Version

rustc 1.21.0 (3b72af97e 2017-10-09)

Affected Version of clap

v2.26.2

Expected Behavior Summary

A global argument (Arg::with_name("vm name").global(true)) should be usable when calling get_matches_from_safe_borrow() multiple times on the same App.

Actual Behavior Summary

The second time clap parses some input it panics and reports "Non-unique argument name: vm name is already in use". (See debug output)

Due to AppSetting::NoBinaryName and get_matches_from_safe_borrow() available I concluded it would be safe to reuse an App instance parsing many input lines. Except for the global arguments other features work well in my REPL-style cli application.

Alternatively I could clone the App and reset it before parsing another line of input. Do you consider reusing the App instance an API misuse and suggest to use clone() and reset, or is this an actual bug that should be fixed?

Steps to Reproduce the issue

Sample Code or Link to Sample Code

https://github.com/tomprogrammer/clap-global-issue

Debug output

https://gist.github.com/tomprogrammer/4063db64a246b3d2d4bf472cec94fbda

@kbknapp
Copy link
Member

kbknapp commented Oct 24, 2017

Would you mind testing this against the the current master branch? I just merged #1075 which deals with global args quite heavily and would like to know if that solves the issue.

@tomprogrammer
Copy link
Author

I updated the demonstration repository to use the current master branch. Unfortunately the PR doesn't fix this issue. I also updated the debug log in the gist linked above.

@kbknapp
Copy link
Member

kbknapp commented Oct 24, 2017

👍

@kbknapp
Copy link
Member

kbknapp commented Oct 24, 2017

I have this fixed in a local branch, I'll upload and put in the PR once I get home today.

@tomprogrammer
Copy link
Author

Thanks for the fast fix and this convenient and powerful crate!

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

No branches or pull requests

2 participants