question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add feature to forbid option be passed multiple times

See original GitHub issue

For example:

@click.option("--string", type=click.STRING)
def echo(string):
    click.echo(string)

when running

echo --string=str1 --string=str2

it will print the second one. I would like to forbid passing it more than once.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
davidismcommented, May 17, 2018

I’m sticking with the current behavior. It allows overriding options defined earlier, which is useful when using alias in the shell or building up a list of args in Python. The behavior seems consistent with Python itself, where later assignment overrides earlier ones.

1reaction
dawranlioucommented, May 15, 2018

I found a work-around that is to turn on the multiple flag and check the option’s length, for example:

import click

@click.command()
@click.option("--string", multiple=True, type=click.STRING)
def echo(string):
    if len(string) > 1:
        raise click.exceptions.BadOptionUsage('--string', 'Only one --string option is allowed.')
    string = string[0]
    click.echo(string)

if __name__ == '__main__':
    echo()

Run it:

$ python cli.py --string=hi
hi
$ python cli.py --string=hi --string=hi2
Usage: issue_955.py [OPTIONS]

Error: Only one --string option is allowed.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage your passes in Wallet on iPhone - Apple Support
Tap the pass, tap the More button , then tap Pass Details. Choose any of the following (not all options are available on...
Read more >
More on data validation - Microsoft Support
To prevent users from copying and filling data by dragging and dropping cells, go to File > Options > Advanced > Editing options...
Read more >
6 Google Forms settings you should know about - Zapier
Multiple -choice questions can be graded in real time—just point out the correct answer, and Google Forms will take care of the grading...
Read more >
curl.1 the man page
Providing -a, --append multiple times has no extra effect. Disable it again with --no-append. Example: curl --upload-file local --append ftp://example.com/.
Read more >
Strict Mode - React
Additional functionality will be added with future releases of React. ... this component multiple times could lead to invalid application state.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found