Exit Code Mappings

退出代码的默认行为如下:

Default behaviour of an exit codes is as:

  • Errors from a command option parsing will result code of 2

  • Any generic error will result result code of 1

  • Obviously in any other case result code is 0

每个 CommandRegistration 都可以定义自己的 Exceptionexit code 之间的映射。实际上,我们都受 Spring Boot 中关于 exit code 的功能所约束,并且直接整合到其中。

Every CommandRegistration can define its own mappings between Exception and exit code. Essentially we’re bound to functionality in Spring Boot regarding exit code and simply integrate into that.

假设有下面将从命令中抛出的异常显示:

Assuming there is an exception show below which would be thrown from a command:

Unresolved include directive in modules/ROOT/pages/commands/exceptionhandling/mappings.adoc - include::../../test/java/org/springframework/shell/docs/ExitCodeSnippets.java[]

可以定义 Throwable 和退出代码之间的映射函数。您还可以只将 class 配置为 exit code,这只是配置中的语法糖。

It is possible to define a mapping function between Throwable and exit code. You can also just configure a class to exit code which is just a syntactic sugar within configurations.

Unresolved include directive in modules/ROOT/pages/commands/exceptionhandling/mappings.adoc - include::../../test/java/org/springframework/shell/docs/ExitCodeSnippets.java[]

退出代码不能用基于注释的配置定制

Exit codes cannot be customized with annotation based configuration