ArgumentParser with 0 arguments doesn't function (flags)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza con el contrato de ArgumentParser.getRequestedArgumentCount y sigue la ruta de registro de CommandFlag y CommandArgument que utiliza el ejemplo --nearest. Reproduce el comando con un parser que devuelva cero argumentos y, a continuación, identifica por qué sigue informando de que falta un argumento. La tarea estará terminada cuando un parser de cero argumentos pueda derivar su valor de CommandContext sin que el flag requiera entrada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When you create your own ArgumentParser that returns 0 in getRequestedArgumentCount(), with the intention of it inspecting the command context to deduce the argument value from there, it doesnt work. I used one with my own flag, --nearest. But when I tried to run the command with --nearest, it gives an error that it expects an argument. Despite argument count being 0.
Another issue is that you can't have a variable number of argument values for a flag, but that's a different issue altogether and less important here.
If there is an alternative way to register a new flag with some sort of 'value supplier' or function CommandContext -> Value, that would be fine too. There's no suggestions and the queue isn't used, anyway, so using an ArgumentParser for this is a bit out of place as well.
Example code:
private static class NearestParser implements ArgumentParser<CommandSender, NearPosition> {
private final LocationArgument.LocationParser<CommandSender> locationParser = new LocationArgument.LocationParser<>();
@Override
public ArgumentParseResult<NearPosition> parse(
final CommandContext<CommandSender> commandContext,
final Queue<String> inputQueue
) {
Queue<String> atSenderQueue = new LinkedList<>();
atSenderQueue.add("~");
atSenderQueue.add("~");
atSenderQueue.add("~");
ArgumentParseResult<Location> locationResult = this.locationParser.parse(commandContext, atSenderQueue);
if (locationResult.getFailure().isPresent()) {
return ArgumentParseResult.failure(
locationResult.getFailure().get()
);
}
// Done!
return ArgumentParseResult.success(new NearPosition(
locationResult.getParsedValue().get(),
128.0));
}
@Override
public List<String> suggestions(
final CommandContext<CommandSender> commandContext,
final String input
) {
return Collections.emptyList();
}
@Override
public int getRequestedArgumentCount() {
return 0;
}
}
private static class NearArgument extends CommandArgument<CommandSender, NearPosition> {
private NearArgument(String name) {
super(true, name, new NearestParser(), "",
TypeToken.get(NearPosition.class),
null,
Collections.emptyList());
}
}
private final CommandFlag<NearPosition> flagNearest = CommandFlag.newBuilder("nearest")
.withArgument(new NearArgument("where"))
.build();
// Somewhere:
builder = builder.flag(flagNearest);
- Lenguaje dominante
- Java
- Estrellas
- 546
- Forks
- 61
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Incendo/cloud
-
Dificultad 2/5 Medio día Aptitud para principiantes 76/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
Todos los issues de Incendo/cloud
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
quelea-projection/Quelea#749 ·
Los mantenedores suelen responder en 1 día
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
erkamyaman/rust-anything#963 ·
Los mantenedores suelen responder en 1 día
-
api-diagnostics bug jdbc
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
ClickHouse/clickhouse-java#3464 ·
Los mantenedores suelen responder en 1 día
-
Deferred
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Sanne/incus-spawn#2768 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
morluto/rea#15041 · 1 comentario ·
Los mantenedores suelen responder en 1 día