【发布时间】:2020-06-04 18:32:31
【问题描述】:
假设我在文件 cli.py 中定义了一个基本的 click CLI 命令:
import click
@click.command()
@click.option('--test-option')
def get_inputs(test_option):
return test_option
然后是另一个模块脚本test_cli.py,我想从中使用上面定义的CLI:
from cli import get_inputs
print('before calling get_inputs')
print(get_inputs())
print('after calling get_inputs')
然后在命令行上:
$ python test_cli.py --test-option test123
before calling get_inputs
所以看起来在运行一个 Click 命令之后,整个 Python 进程就完成了,即使在启动调用的脚本中在该 Click 命令之后有要评估的语句和表达式,它们也不会被执行。我将如何实现这一目标?
【问题讨论】:
标签: python command-line-interface python-click