Clap: Using a binary name with an underscore leads to panic on completion generation

Created on 14 Jul 2016  路  17Comments  路  Source: clap-rs/clap

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

generator subcommands urgent bug 2.x

All 17 comments

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,

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

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

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 :wink:

@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 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.

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

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

@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.

@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.

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 :wink:

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

@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.

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.

@kbknapp thanks for looking into it.

Now I can use auto completion too :-).

@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!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kbknapp picture kbknapp  路  22Comments

matchai picture matchai  路  19Comments

kbknapp picture kbknapp  路  18Comments

smklein picture smklein  路  35Comments

RazrFalcon picture RazrFalcon  路  16Comments