python click option code example

Example 1: import click click.echo() .format python 3

import click

@click.command()
@click.option('--verbose', is_flag=True, help="Will print verbose messages.")
@click.option('--name', '-n', multiple=True, default='', help='Who are you?')
@click.argument('country')
def cli(verbose,name, country):
    """This is an example script to learn Click."""
    if verbose:
        click.echo("We are in the verbose mode.")
    click.echo("Hello {0}".format(country))
    for n in name:
        click.echo('Bye {0}'.format(n))

Example 2: what does @click.option do python

# It supplies options to be use in a command line interface. 
# Much like the --help option that you see.
# With this you can create your own options like count and name.
# ex.
import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', default='John,
              help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo('Hello %s!' % name)

if __name__ == '__main__':
    hello()
    
# output
$ python hello.py --count=3

Hello John!