Python 如何在两个@click.option()之间打印自定义消息?

Python 如何在两个@click.option()之间打印自定义消息?,python,python-3.x,command-line-interface,python-click,Python,Python 3.x,Command Line Interface,Python Click,我正在使用Python包编写一个命令行工具 我想在两个@click.option()之间打印一条自定义消息 以下是我想要实现的示例代码: import click @click.command() @click.option('--first', prompt='enter first input') print('custom message') # want to print custom message here @click.option('--second', prompt='en

我正在使用Python包编写一个命令行工具

我想在两个
@click.option()
之间打印一条自定义消息

以下是我想要实现的示例代码:

import click


@click.command()
@click.option('--first', prompt='enter first input')
print('custom message') # want to print custom message here
@click.option('--second', prompt='enter second input')
def add_user(first, second):
    print(first)
    print(second)


add_user()
有什么帮助吗?我怎么做


提前感谢。

您可以对第一个参数使用回调:

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