ArgumentParser with 0 arguments doesn't function (flags)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với contract của ArgumentParser.getRequestedArgumentCount và lần theo đường đi đăng ký CommandFlag và CommandArgument được ví dụ --nearest sử dụng. Tái hiện command bằng một parser trả về không đối số, sau đó xác định tại sao nó vẫn báo thiếu đối số. Hoàn thành khi parser không có đối số có thể suy ra giá trị từ CommandContext mà flag không yêu cầu input.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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);
- Ngôn ngữ chính
- Java
- Star
- 546
- Fork
- 61
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Incendo/cloud
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Tất cả issue của Incendo/cloud
Issue tương tự
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Deferred
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Sanne/incus-spawn#2768 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
morluto/rea#15041 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Spring SDK returns null for successful plain-text String responsesCó thể đã có người làm @Chrisp12138 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày