Command Not Found

在默认情况下,缺失的命令由 CommandNotFoundResultHandler 处理,并输出一条简单消息:

On default a missing command is handled via CommandNotFoundResultHandler and outputs a simple message:

shell:>missing
No command found for 'missing'

在内部,CommandNotFoundResultHandler 使用 CommandNotFoundMessageProvider,它是一个简单函数,可以将 ProviderContext 作为输入,并返回一条文本消息。以下是自定义消息提供程序可能的样子之一。

Internally CommandNotFoundResultHandler is using CommandNotFoundMessageProvider which is a simple function taking a ProviderContext and returning a text message. Below is an example what a custom message provider might look like.

Unresolved include directive in modules/ROOT/pages/customization/commandnotfound.adoc - include::../../test/java/org/springframework/shell/docs/CommandNotFoundSnippets.java[]

可以通过将其定义为一个 bean 来更改此实现。

It’s possible to change this implementation by defining it as a bean.

Unresolved include directive in modules/ROOT/pages/customization/commandnotfound.adoc - include::../../test/java/org/springframework/shell/docs/CommandNotFoundSnippets.java[]

CommandNotFoundResultHandler 是一个函数式接口,因此它可以作为 lambda 来编写。

CommandNotFoundResultHandler is a functional interface so it can be writter as a lambda.

Unresolved include directive in modules/ROOT/pages/customization/commandnotfound.adoc - include::../../test/java/org/springframework/shell/docs/CommandNotFoundSnippets.java[]