当 Click 以退出代码 2 退出时,这意味着什么?
What does it mean when Click exits with exit code 2?
我目前 testing a Click CLI application 并且得到 result.exit_code == 2
。为什么会这样?
我运行
result = runner.invoke(cli, ['sync'])
而不是
result = runner.invoke(cli, ['--debug', 'sync'])
因此您需要指定通过 CLI 输入的标志,如果您使用 @click.option
,则不仅要传递函数使用的参数。
此外,我对其中一个标志打错了字。
如何调试
- 看你传递给
runner.invoke
的参数(最简单:打印出来)
- 通过 CLI 执行它(例如
cli(['--debug', 'sync'])
)
就我而言,这给了我消息
Error: no such option: --sync Did you mean --syncs?
这似乎表明 usage error:
An internal exception that signals a usage error. This typically aborts any further handling.
这与Click自己的测试一致,例如
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L82
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L190
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L201
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L157
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L177
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L193
我目前 testing a Click CLI application 并且得到 result.exit_code == 2
。为什么会这样?
我运行
result = runner.invoke(cli, ['sync'])
而不是
result = runner.invoke(cli, ['--debug', 'sync'])
因此您需要指定通过 CLI 输入的标志,如果您使用 @click.option
,则不仅要传递函数使用的参数。
此外,我对其中一个标志打错了字。
如何调试
- 看你传递给
runner.invoke
的参数(最简单:打印出来) - 通过 CLI 执行它(例如
cli(['--debug', 'sync'])
)
就我而言,这给了我消息
Error: no such option: --sync Did you mean --syncs?
这似乎表明 usage error:
An internal exception that signals a usage error. This typically aborts any further handling.
这与Click自己的测试一致,例如
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L82
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L190
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L201
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L157
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L177
- https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L193