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

clap_complete: incorrect args appear on nested subcommands with the same name #5242

Closed
2 tasks done
m4rch3n1ng opened this issue Dec 3, 2023 · 1 comment
Closed
2 tasks done
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-hard Call for participation: Experience needed to fix: Hard / a lot

Comments

@m4rch3n1ng
Copy link

m4rch3n1ng commented Dec 3, 2023

Please complete the following tasks

Rust Version

rustc 1.75.0-beta.4 (bd45872d9 2023-11-28)

Clap Version

[[package]]
name = "clap"
version = "4.4.10"

Minimal reproducible code

use clap::{Args, CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell};

#[derive(Parser)]
struct Cli {
	#[command(subcommand)]
	sub: Option<Top>,
}

#[derive(Subcommand)]
enum Top {
	Config(TopConfigArgs),
	Sync(SyncArgs),
}

#[derive(Args)]
struct TopConfigArgs {
	/// should only appear for top level config
	#[arg(long)]
	test: bool,
}

#[derive(Args)]
struct SyncArgs {
	#[command(subcommand)]
	pub sub: SyncCmd,
}

#[derive(Subcommand)]
enum SyncCmd {
	Config,
}

fn main() {
	let _ = Cli::parse();

	let mut cli = Cli::command();
	generate(Shell::Fish, &mut cli, "stuff", &mut std::io::stdout());
}

Steps to reproduce the bug with the above code

(only tested in fish shell)

$ cargo run > complete.fish
$ source complete.fish

and then test the completions for stuff config -- and stuff sync config --

Actual Behaviour

it works as expected if you try to complete for stuff config --

image

but it also shows it as a possible argument for stuff sync config

image

even though running cargo run -- sync config --test gives an unexpected argument error

image

Expected Behaviour

i would expect the --test option to not be suggested for stuff sync config

Additional Context

$ grep -C1 clap Cargo.lock
[[package]]
name = "clap"
version = "4.4.10"
# -- snip --
[[package]]
name = "clap_complete"
version = "4.4.4"

Debug Output

No response

@m4rch3n1ng m4rch3n1ng added the C-bug Category: Updating dependencies label Dec 3, 2023
@epage epage added E-hard Call for participation: Experience needed to fix: Hard / a lot A-completion Area: completion generator labels Dec 4, 2023
@epage
Copy link
Member

epage commented Aug 10, 2024

As I believe this is resolved with the native completions, I'm going to close this. If this was incorrect, let us know!

You can track stabilization at #3166

@epage epage closed this as completed Aug 10, 2024
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 E-hard Call for participation: Experience needed to fix: Hard / a lot
Projects
None yet
Development

No branches or pull requests

2 participants