ArgumentParser with 0 arguments doesn't function (flags)

Ouverte
#379 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
java
Domaine
cli

Piste de recherche

Commencez par le contrat de ArgumentParser.getRequestedArgumentCount et suivez le chemin d’enregistrement de CommandFlag et CommandArgument utilisé par l’exemple --nearest. Reproduisez la commande avec un analyseur qui renvoie zéro argument, puis identifiez pourquoi un argument manquant est toujours signalé. La tâche est terminée lorsqu’un analyseur sans argument peut déduire sa valeur depuis CommandContext sans que le flag exige une entrée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug

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);
Langage dominant
Java
Étoiles
546
Forks
61
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Incendo/cloud

Toutes les issues de Incendo/cloud

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.