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

Using a binary name with an underscore leads to panic on completion generation #581

Closed
ruabmbua opened this issue Jul 14, 2016 · 17 comments
Closed
Assignees
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Milestone

Comments

@ruabmbua
Copy link

ruabmbua commented Jul 14, 2016

I tried to upgrade clap-rs on my command line utility and include the new awesome bash completion generation in my build.rs file. I followed the recommendation to how do things in the docs, but my build.rs files panics at execution.

Error backtrace

I think the error is sub command related becaue of this line of code, where the nasty unwrap lies: Bad Code

The code used for clap::App generation looks like this: The Code

@ruabmbua ruabmbua changed the title Unwrap panics on completions generation Unwrap panic on completions generation Jul 14, 2016
@guiniol
Copy link

guiniol commented Jul 21, 2016

Hello,

I think I have the same error, but I'm using the standard way of declaring subcommands and args.
I tried removing the subcommands and in that case it works. I'm pretty new to Rust and it's my first time using clap, so I may be doing some things wrong.

For a small test case, see https://github.com/guiniol/dnsmole . It doesn't do anything except handle subcommands and args for now. Trying to run dnsmole serve target gives the same thread '<main>' panicked at 'calledOption::unwrap()on aNonevalue', src/libcore/option.rs:325

Cheers,

@ruabmbua
Copy link
Author

I do not use subcommands at all, but it still crashes.

@guiniol
Copy link

guiniol commented Jul 23, 2016

So. I did a bit more testing and the problem seems to positional arguments in subcommands
We should maybe close this one and open a new issue.
EDIT: opened #592

@kbknapp
Copy link
Member

kbknapp commented Jul 23, 2016

Thanks for filing this! I'm going through all the issues and PRs that accumulated while I was traveling. I should be able to get to this shortly. I'll post back with any questions or findings 😉

@kbknapp kbknapp self-assigned this Jul 23, 2016
@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-completion Area: completion generator labels Jul 23, 2016
@kbknapp kbknapp added this to the 2.10.1 milestone Aug 20, 2016
@kbknapp
Copy link
Member

kbknapp commented Aug 20, 2016

@ruabmbua I'm finally back from all my travels. Can you give me some more details on this error? I'm not quite clear on what code is making it panic.
Could you give a static-reference to the line of code that you think is causing the error? Press 'y' on the github page, then link to the line.

If we can't figure it out that way, you can compile clap with the debug feature which will spit out all kinds of debugging info that can be helpful. Just change your Cargo.toml to

[dependencies]
clap = {version = "2.10.0", features = ["debug"] }

@kbknapp kbknapp removed this from the 2.10.1 milestone Aug 20, 2016
@ruabmbua
Copy link
Author

@kbknapp sadly I am going on a travel for a week starting today ^^. I already noticed, that my line markings in the github links are wrong, but you could try finding the line by checking out the HEAD from the issues creation date.

@kbknapp
Copy link
Member

kbknapp commented Aug 21, 2016

Ah ok, I see now. I'll do some testing and see what I can find.

@kbknapp kbknapp modified the milestone: 2.10.5 Aug 26, 2016
@lukaspustina
Copy link

lukaspustina commented Nov 8, 2016

Just pinging: Any updates on this issue? I'm observing the same for 'bash' and 'zsh' in clap 2.18.0.

@kbknapp
Copy link
Member

kbknapp commented Nov 8, 2016

@lukaspustina can you give me a minimal example that's causing the panic?

Also, if you compile clap with the debug cargo feature it'll spit out tons of data you could paste into a gist or here that'll help track down the issue.

@lukaspustina
Copy link

@kbknapp sorry, I should have presented more information. I'll be quite busy today, but might be able to prepare what you're asking for tmr. Meanwhile, if you're interested, I created a branch of my project in which the problem occurs; cf. https://github.com/lukaspustina/bosun_emitter/tree/shell_completions.

@kbknapp
Copy link
Member

kbknapp commented Nov 9, 2016

Thanks, I'll try to do the testing tonight after work on that branch. Once I check the debug output, I should be able to see where the problem lies and won't need the minimal test case 😉

@lukaspustina
Copy link

Alright. Please let me know, if I can be of any assistance.

@kbknapp
Copy link
Member

kbknapp commented Nov 10, 2016

@ruabmbua @lukaspustina

I found the issue. This is caused by having a binary name that includes an underscore (_). The reasoning behind this is the bash completions use the underscore character to handle subcommands.

The quick fix is to use a binary name that doesn't include an underscore. I'll work on a solution to work around this in clap but it may be complicated. At the very least, this should be documented in the completion documentations.

@kbknapp kbknapp changed the title Unwrap panic on completions generation Using a binary name with an underscore leads to panic on completion generation Nov 10, 2016
@lukaspustina
Copy link

Hi @kbknapp,

thanks for looking into the issue and finding the reason. Unfortunately, renaming the binary is not an option since we use it in a many scripts. But I'm patient and wait until you'll find time to fix the underlying problems.

Thanks again.

@ruabmbua
Copy link
Author

@kbknapp thanks for looking into it.

Now I can use auto completion too :-).

@kbknapp kbknapp modified the milestones: 2.20.2, 2.20.3 Jan 30, 2017
kbknapp added a commit that referenced this issue Feb 3, 2017
kbknapp added a commit that referenced this issue Feb 3, 2017
@kbknapp
Copy link
Member

kbknapp commented Feb 3, 2017

@lukaspustina once #843 merges I'll put out v2.20.3 on crates.io at which point completion works even with underscores in the names. Apologies for the wait!

@lukaspustina
Copy link

@kbknapp Don't you worry. I'm happy you found time to fix this :)
Please ping me once the crate is updates. TIA.

kbknapp added a commit that referenced this issue Feb 3, 2017
kbknapp added a commit that referenced this issue Feb 3, 2017
kbknapp added a commit that referenced this issue Feb 3, 2017
kbknapp added a commit that referenced this issue Feb 3, 2017
@kbknapp kbknapp closed this as completed in 92919f5 Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

4 participants