Skip to content Skip to sidebar Skip to footer

How To Print A Custom Message Between Two @click.option()?

I'm writing a command-line tool using Python Click package. I want to print a custom message between two @click.option(). Here is the sample code for what I want to achieve: import

Solution 1:

You can use a callback on the first argument:

import click

def print_message(ctx, param, args):
    print("Hi")
    return args

@click.command()
@click.option('--first', prompt='enter first input', callback=print_message)
@click.option('--second', prompt='enter second input')
def add_user(first, second):
    print(first)
    print(second)


add_user()

$ python3.8 user.py 
enter first input: one
Hi
enter second input: two
one
two

Post a Comment for "How To Print A Custom Message Between Two @click.option()?"