Fix availability feature
- Bring back some missing functionality which got missing during the rework to new command model. - Polish some classes. - Restore origin sample. - Add availability things into help templates and its representation model. - Fixes #423
This commit is contained in:
@@ -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.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.shell;
|
||||
|
||||
/**
|
||||
@@ -23,20 +22,21 @@ package org.springframework.shell;
|
||||
*/
|
||||
public class CommandNotCurrentlyAvailable extends RuntimeException {
|
||||
|
||||
private final String command;
|
||||
private final Availability availability;
|
||||
private final String command;
|
||||
private final Availability availability;
|
||||
|
||||
public CommandNotCurrentlyAvailable(String command, Availability availability) {
|
||||
super(String.format("Command '%s' exists but is not currently available because %s", command, availability.getReason()));
|
||||
this.command = command;
|
||||
this.availability = availability;
|
||||
}
|
||||
public CommandNotCurrentlyAvailable(String command, Availability availability) {
|
||||
super(String.format("Command '%s' exists but is not currently available because %s", command,
|
||||
availability.getReason()));
|
||||
this.command = command;
|
||||
this.availability = availability;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public Availability getAvailability() {
|
||||
return availability;
|
||||
}
|
||||
public Availability getAvailability() {
|
||||
return availability;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.shell.Availability;
|
||||
import org.springframework.shell.CommandNotCurrentlyAvailable;
|
||||
import org.springframework.shell.command.CommandParser.CommandParserException;
|
||||
import org.springframework.shell.command.CommandParser.CommandParserResults;
|
||||
import org.springframework.shell.command.CommandRegistration.TargetInfo;
|
||||
@@ -95,6 +97,11 @@ public interface CommandExecution {
|
||||
}
|
||||
|
||||
public Object evaluate(CommandRegistration registration, String[] args) {
|
||||
// fast fail with availability before doing anything else
|
||||
Availability availability = registration.getAvailability();
|
||||
if (availability != null && !availability.isAvailable()) {
|
||||
return new CommandNotCurrentlyAvailable(registration.getCommand(), availability);
|
||||
}
|
||||
|
||||
List<CommandOption> options = registration.getOptions();
|
||||
CommandParser parser = CommandParser.of(conversionService);
|
||||
|
||||
Reference in New Issue
Block a user