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

Flag parsing error when flag value matches subcommand name #1913

Closed
watsonian opened this issue Feb 15, 2023 · 5 comments
Closed

Flag parsing error when flag value matches subcommand name #1913

watsonian opened this issue Feb 15, 2023 · 5 comments

Comments

@watsonian
Copy link

I seem to have run into a bug that surfaces when you pass a value into a flag that matches the name of a subcommand. For example, suppose you have a command like this:

tester --project configs --config dev configs

where configs is a subcommand, but we're also passing that in as the value to the --project flag. In that scenario, the value for project ends up being --config and the value for config ends up being empty. If you change the value being passed to --project to anything else, it works fine. It also starts working fine if you leave the value being passed to --project as is, but rename the subcommand.

Here's video demonstrating the issue:

https://www.loom.com/share/22d1caba74644c939e978fd3277a437d

And here's the sample code demonstrating the problem: cobra-tester.zip

@marckhouzam
Copy link
Collaborator

Is this the same as #1777 ?

@watsonian
Copy link
Author

@marckhouzam Definitely sounds like the same issue, yeah. Seems like it's not actually fixed.

@marckhouzam
Copy link
Collaborator

marckhouzam commented Feb 25, 2023

Duplicate #1777

Thanks for the test program @watsonian. I did see the problem with it. So I wondered if you were using an old version of cobra but you were not. This is when I realized that the fix for this hasn't been released yet 😄 , as we can see from the milestone set for #1781 .

I have re-tried your test program with the main branch of cobra and it properly works in that case.

@watsonian
Copy link
Author

@marckhouzam It looks like the actual fix for this was merged 4 months ago and still isn't released. Do you know when the next release will be?

@marckhouzam
Copy link
Collaborator

We usually do releases every four months, so one should be coming up soon.

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