Python Forum
key=value style command argument parser
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
key=value style command argument parser
#7
A example with Click.
# dig.py
import click

@click.command()
@click.option('--hash', type=click.Choice(['MD5', 'SHA1'], case_sensitive=False))
def digest(hash):
    click.echo(f'Your choice is <{hash}>')

if __name__ == '__main__':
    digest()
Output:
E:\div_code λ python dig.py --hash=MD5 Your choice is <MD5> E:\div_code λ python dig.py --hash=SHA1 Your choice is <SHA1> E:\div_code λ python dig.py --hash=foo Usage: dig.py [OPTIONS] Try "dig.py --help" for help. Error: Invalid value for "--hash": invalid choice: foo. (choose from MD5, SHA1) E:\div_code λ python dig.py --help Usage: dig.py [OPTIONS] Options: --hash [MD5|SHA1] --help Show this message and exit.
Reply


Messages In This Thread
RE: key=value style command argument parser - by snippsat - Dec-02-2019, 09:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  my own command line option parser Skaperen 0 1,673 Mar-27-2020, 04:14 AM
Last Post: Skaperen
  argument for the python command Skaperen 0 2,653 Dec-05-2019, 11:30 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020