-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
zsh: optional flag with takes_value breaks completions #1822
Comments
@intgr I couldn't reproduce this when this issue was created. Do you want to take a look at this? |
This is a bug indeed, the same issue affects zsh built-in
EDIT: Sorry, my bad, the above works with I'll have to dig some more in zsh documentation to see if this is can be fixed in clap or if it's a bug in zsh itself. If this is helpful for anyone, here's clap 3.x compatible version of the bug report's code:use clap::{App, Arg};
use clap_generate::generators::{Bash, Zsh};
use std::io::stdout;
fn app() -> App<'static> {
App::new("completion-bug")
.arg(Arg::new("foo").short('f').long("foo").takes_value(true))
.subcommand(App::new("zsh"))
.subcommand(App::new("bash"))
}
fn main() {
let args = app().get_matches();
eprintln!("{:?}", args);
match args.subcommand() {
("zsh", _) => {
let mut app = app();
clap_generate::generate::<Zsh, _>(&mut app, "completion-bug", &mut stdout());
}
("bash", _) => {
let mut app = app();
clap_generate::generate::<Bash, _>(&mut app, "completion-bug", &mut stdout());
}
_ => unreachable!(),
};
} |
As far as I can tell, clap is annotating the arguments correctly per zsh documentation (http://zsh.sourceforge.net/Doc/Release/Completion-System.html) From the generated file:
Documentation:
I looked at git completions and I still don't understand why I don't consume the sort of hard drugs necessary to get in the same frame of mind as zsh developers, I don't wish to investigate this further, sorry. :) |
Thanks for your help @intgr |
It seems to work fine for me using the latest versions (clap v4.3.11, clap_complete v4.3.2). Here is the updated code I useduse clap::{value_parser, Arg, Command};
use clap_complete::Shell;
use std::{io::stdout, path::PathBuf};
fn app() -> Command {
Command::new("completion-bug")
.arg(
Arg::new("foo")
.short('f')
.long("foo")
.value_parser(value_parser!(PathBuf)),
)
.subcommand(Command::new("zsh"))
.subcommand(Command::new("bash"))
}
fn main() {
let args = app().get_matches();
eprintln!("{:?}", args);
let shell = match args.subcommand() {
Some(("zsh", _)) => Shell::Zsh,
Some(("bash", _)) => Shell::Bash,
_ => unreachable!(),
};
clap_complete::generate(shell, &mut app(), "completion-bug", &mut stdout());
} |
I also tried again and can confirm zsh tab completions are now working correctly. Thanks whoever did this! ❤️ |
Make sure you completed the following tasks
Code
Steps to reproduce the issue
Version
Actual Behavior Summary
completion-bug -f x z<tab>
doesn't complete anything.This affects https://github.com/kpcyrd/sn0int because it has a lot of nested subcommands but it's very common to start the command with
sn0int -w foo
which breaks the completions for everything afterwards.The bash completions work correctly.
Expected Behavior Summary
completion-bug -f x z<tab>
should complete tocompletion-bug -f x zsh
Additional context
This bug was originally reported as TeXitoi/structopt#369 and then ported over to pure clap. The completions generated by the structopt program and the clap program are identical.
The text was updated successfully, but these errors were encountered: