Skip to content

Prioritizing full parameter validation before prompting #1369

@sphuber

Description

@sphuber

I am faced with the following problem. Imagine the following dummy script:

#!/usr/bin/env python
import click

@click.command()
@click.option('--name', prompt=True)
def main(name):
    click.echo(name)

if __name__ == '__main__':
    main()

When invoked with an unexpected argument, e.g. test.py extra_argument instead of failing straight away, first the prompt is invoked. When the prompt is responded to, only then does the command fail:

Name: test
Usage: test_argument.py [OPTIONS]
Try "test_argument.py --help" for help.

Error: Got unexpected extra argument (extra)

Now for a single option, this is not a big deal. However, in our application we have a command with many options with prompt. If the user accidentally pass an argument, they first have to respond to all the prompts only for the command to error out straight after and they have to start all over again.

Is there any way to prioritize parsing of all parameters before hitting prompts of incomplete ones?

Metadata

Metadata

Assignees

No one assigned

    Labels

    f:promptfeature: prompt for input

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions