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

Order of options / command name seems to matter #245

Closed
marktheunissen opened this issue Nov 12, 2014 · 4 comments
Closed

Order of options / command name seems to matter #245

marktheunissen opened this issue Nov 12, 2014 · 4 comments

Comments

@marktheunissen
Copy link

Hello,

If I have options, it seems to be mandatory that they appear before the command name, as putting them after triggers a 'no such option' error.

Test code:

import click

@click.group()
@click.option('--abc', default=2)
@click.option('--defg', default=2)
def cli(abc, defg):
    click.echo('Options passed were %s / %s' % (abc,defg))

@cli.command()
def sync():
    click.echo('Synching')

if __name__ == '__main__':
    cli()

This doesn't work:

$ test.py sync --defg=6
Options passed were 2 / 2
Error: no such option: --defg

This works:

$ test.py --defg=6 sync
Options passed were 2 / 6
Synching

It may be that the options must come before the command, but then for example I see in one of the tests:

Usage: foo test [OPTIONS]

And I also have received a message before saying Usage: <script> command [OPTIONS] where the options were listed last in the list.

Perhaps just a better error message instead of no such option?

Thanks!
Mark

@marktheunissen
Copy link
Author

On version 3.3, I see the different ordering recommended in the Usage help text:

$ test.py sync --defg=6
Options passed were 2 / 2
Usage: test.py sync [OPTIONS]

Error: no such option: --defg

@untitaker
Copy link
Contributor

Duplicate of #108, see explanations there.

@marktheunissen
Copy link
Author

Thanks. This issue could remain open to perhaps add a better error message, as I spent ages trying to figure this out. Change it to:

Error: no such option on the command, perhaps it is a group option?

@mitsuhiko
Copy link
Contributor

This is intentional.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants