Add AbstractSWCommand.OptionalValue.onlyUINIG
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-08-22 18:07:35 +02:00
Ursprung 6cb3bc5ff5
Commit 3829cd6706
3 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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)

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);
}