I am using click framework.I want to return version and exit code when I run python hello.py --version. Currently my code is like this.
import click
def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
click.echo('Version 1.0')
return 1
ctx.exit()
@click.command()
@click.option('--version', is_flag=True, callback=print_version,
expose_value=False, is_eager=True)
def hello():
click.echo('Hello World!')
hello()
$ python hello.py --version
Version 1.0
Hello World!
I am expecting an output like this:
$ python hello.py --version
Version 1.0
1
hello()function toclick.echo(1)you will get your expected output. Is that what you were looking for?