Separate interactive and non-interactive commands
- Add new ShellContext concept which now is just a way to stash info about interaction mode where ShellRunner can update supported mode. - ShellMethod has a new field interactionMode which user can use to define commands between interactive/non-interactive modes which then prevents CommandRegistry to show commands at runtime. - Fixes #345
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2021 the original author or authors.
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.shell.standard.commands;
|
||||
|
||||
import org.jline.utils.InfoCmp;
|
||||
|
||||
import org.springframework.shell.context.InteractionMode;
|
||||
import org.springframework.shell.standard.AbstractShellComponent;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
@@ -47,7 +48,7 @@ public class Clear extends AbstractShellComponent {
|
||||
public Clear() {
|
||||
}
|
||||
|
||||
@ShellMethod("Clear the shell screen.")
|
||||
@ShellMethod(value = "Clear the shell screen.", interactionMode = InteractionMode.INTERACTIVE)
|
||||
public void clear() {
|
||||
getTerminal().puts(InfoCmp.Capability.clear_screen);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.shell.standard.commands;
|
||||
|
||||
import org.springframework.shell.ExitRequest;
|
||||
import org.springframework.shell.context.InteractionMode;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class Quit {
|
||||
*/
|
||||
public interface Command {}
|
||||
|
||||
@ShellMethod(value = "Exit the shell.", key = {"quit", "exit"})
|
||||
@ShellMethod(value = "Exit the shell.", key = {"quit", "exit"}, interactionMode = InteractionMode.INTERACTIVE)
|
||||
public void quit() {
|
||||
throw new ExitRequest();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2021 the original author or authors.
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.shell.standard.commands;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.shell.context.InteractionMode;
|
||||
import org.springframework.shell.result.ThrowableResultHandler;
|
||||
import org.springframework.shell.standard.AbstractShellComponent;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
@@ -49,7 +50,9 @@ public class Stacktrace extends AbstractShellComponent {
|
||||
this.throwableResultHandler = throwableResultHandler;
|
||||
}
|
||||
|
||||
@ShellMethod(key = ThrowableResultHandler.DETAILS_COMMAND_NAME, value = "Display the full stacktrace of the last error.")
|
||||
@ShellMethod(key = ThrowableResultHandler.DETAILS_COMMAND_NAME,
|
||||
value = "Display the full stacktrace of the last error.",
|
||||
interactionMode = InteractionMode.INTERACTIVE)
|
||||
public void stacktrace() {
|
||||
if (throwableResultHandler.getIfAvailable().getLastError() != null) {
|
||||
throwableResultHandler.getIfAvailable().getLastError().printStackTrace(getTerminal().writer());
|
||||
|
||||
Reference in New Issue
Block a user