ArgumentParser with 0 arguments doesn't function (flags)
还没有人认领这个 Issue。
评估
调研方向
从 ArgumentParser.getRequestedArgumentCount 的契约开始,跟踪 --nearest 示例使用的 CommandFlag 和 CommandArgument 注册路径。使用返回零个参数的解析器重现该命令,然后确定它为什么仍然报告缺少参数。当零参数解析器可以从 CommandContext 推导出其值,而无需 flag 要求输入时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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);
- 主要语言
- Java
- 星标
- 546
- 派生
- 61
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Incendo/cloud 的其他 Issue
-
难度 2/5 半天 新手友好度 76/100
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 50/100
-
难度 4/5 3-5 天 新手友好度 30/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 92/100
erkamyaman/rust-anything#963 ·
维护者通常 1 天内回复
-
Deferred
难度 2/5 1-3 小时 新手友好度 78/100
Sanne/incus-spawn#2768 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
[BUG] Spring SDK returns null for successful plain-text String responses可能已有人在做 @Chrisp12138 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复