Add AbstractSWCommand.OptionalValue.onlyUINIG
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
6cb3bc5ff5
Commit
3829cd6706
@ -386,6 +386,11 @@ public abstract class AbstractSWCommand<T> {
|
||||
* Will pe parsed against the TypeMapper specified by the parameter or annotation.
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* The method name stands for 'onlyUseIfNoneIsGiven'.
|
||||
*/
|
||||
boolean onlyUINIG() default false;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -23,7 +23,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -52,6 +51,9 @@ class CommandPart<T> {
|
||||
@Setter
|
||||
private boolean ignoreAsArgument = false;
|
||||
|
||||
@Setter
|
||||
private boolean onlyUseIfNoneIsGiven = false;
|
||||
|
||||
public CommandPart(AbstractSWCommand<T> command, AbstractTypeMapper<T, ?> typeMapper, AbstractValidator<T, Object> validator, AbstractGuardChecker<T> guardChecker, Class<?> varArgType, String optional, GuardCheckType guardCheckType) {
|
||||
this.command = command;
|
||||
this.typeMapper = typeMapper;
|
||||
@ -113,7 +115,11 @@ class CommandPart<T> {
|
||||
}
|
||||
if (!validArgument.success) {
|
||||
if (!ignoreAsArgument) {
|
||||
current.add(typeMapper.map(sender, EMPTY_ARRAY, optional));
|
||||
if (!onlyUseIfNoneIsGiven) {
|
||||
current.add(typeMapper.map(sender, EMPTY_ARRAY, optional));
|
||||
} else if(startIndex >= args.length) {
|
||||
current.add(typeMapper.map(sender, EMPTY_ARRAY, optional));
|
||||
}
|
||||
}
|
||||
if (next != null) {
|
||||
next.generateArgumentArray(errors, current, sender, args, startIndex);
|
||||
|
@ -101,6 +101,7 @@ public class SWCommandUtils {
|
||||
AbstractSWCommand.OptionalValue optionalValue = parameter.getAnnotation(AbstractSWCommand.OptionalValue.class);
|
||||
|
||||
CommandPart<T> commandPart = new CommandPart<>(command, typeMapper, validator, guardChecker, varArgType, optionalValue != null ? optionalValue.value() : null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND);
|
||||
commandPart.setOnlyUseIfNoneIsGiven(optionalValue != null && optionalValue.onlyUINIG());
|
||||
if (current != null) {
|
||||
current.setNext(commandPart);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren