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 2015 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
@@ -22,6 +21,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.shell.context.InteractionMode;
|
||||
|
||||
/**
|
||||
* Used to mark a method as invokable via Spring Shell.
|
||||
*
|
||||
@@ -68,4 +69,14 @@ public @interface ShellMethod {
|
||||
*/
|
||||
String group() default INHERITED;
|
||||
|
||||
/**
|
||||
* Defines interaction mode for a command as a hint when command should be
|
||||
* available. For example presense of some commands doesn't make sense if shell
|
||||
* is running as non-interactive mode and vice versa.
|
||||
*
|
||||
* Defaults to {@link InteractionMode#ALL}
|
||||
*
|
||||
* @return interaction mode
|
||||
*/
|
||||
InteractionMode interactionMode() default InteractionMode.ALL;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -76,7 +75,8 @@ public class StandardMethodTargetRegistrar implements MethodTargetRegistrar, App
|
||||
String group = getOrInferGroup(method);
|
||||
for (String key : keys) {
|
||||
Supplier<Availability> availabilityIndicator = findAvailabilityIndicator(keys, bean, method);
|
||||
MethodTarget target = new MethodTarget(method, bean, new Command.Help(shellMapping.value(), group), availabilityIndicator);
|
||||
MethodTarget target = new MethodTarget(method, bean, new Command.Help(shellMapping.value(), group),
|
||||
availabilityIndicator, shellMapping.interactionMode());
|
||||
registry.register(key, target);
|
||||
commands.put(key, target);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user