How to tell whether an argument in click coming from the user or it’s the default value.
For example:
import click
@click.command()
@click.option('--value', default=1, help='a value.')
def hello(value):
print(value)
if __name__ == "__main__":
hello()
Now if I run python script.py --value 1, the value is now coming from user input as opposed to default value (which is set to 1). Is there any way to discern where this value is coming from?
>Solution :
You can check with is_default() method like below:
import click
@click.command()
@click.option('--value', default=1, help='a value.')
def hello(value):
if click.Option.is_default(value):
print("The value is not from user input")
else:
print("The value is from user input")
if __name__ == "__main__":
hello()