Skip to content

Flag parsing error when flag value matches subcommand name #1913

@watsonian

Description

@watsonian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions