当 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,则不仅要传递函数使用的参数。

此外,我对其中一个标志打错了字。

如何调试

  1. 看你传递给runner.invoke的参数(最简单:打印出来)
  2. 通过 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自己的测试一致,例如