Skip to content

Command not found message should be configurable #778

Closed
@jvalkeal

Description

@jvalkeal

ThrowableResultHandler also handles CommandNotFound and thus we get rather long message which really is meant for last resort:

No command found for 'wrong'
org.springframework.shell.CommandNotFound: No command found for 'wrong'
        at org.springframework.shell.Shell.evaluate(Shell.java:205)
        at org.springframework.shell.Shell.run(Shell.java:158)
        at org.springframework.shell.jline.NonInteractiveShellRunner.run(NonInteractiveShellRunner.java:129)
        at org.springframework.shell.DefaultShellApplicationRunner.run(DefaultShellApplicationRunner.java:65)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:761)
...

While it has always been possible to customise by adding a new bean something like:

public class CommandNotFoundResultHandler extends TerminalAwareResultHandler<CommandNotFound> {

	protected CommandNotFoundResultHandler(Terminal terminal) {
		super(terminal);
	}

	@Override
	protected void doHandleResult(CommandNotFound result) {
		terminal.writer().println("hello");
		terminal.writer().flush();
	}

}

It'd be nice we handle "command not found" centrally and make it easier configure and extend. We could have some kind of "context" what a new implementation could use to describe better error.

In 3.2.x we should make this default behaviour and in older versions allow user to enable it(don't want to change default behaviour).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions