-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DurationArgument
for parsing java.time.Duration
#330
Conversation
...src/test/java/cloud/commandframework/arguments/standard/DurationArgumentSuggestionsTest.java
Outdated
Show resolved
Hide resolved
cloud-core/src/main/java/cloud/commandframework/arguments/standard/DurationArgument.java
Outdated
Show resolved
Hide resolved
cloud-core/src/main/java/cloud/commandframework/arguments/standard/DurationArgument.java
Outdated
Show resolved
Hide resolved
cloud-core/src/main/java/cloud/commandframework/arguments/standard/DurationArgument.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some things to make gradle happy
...src/test/java/cloud/commandframework/arguments/standard/DurationArgumentSuggestionsTest.java
Show resolved
Hide resolved
cloud-core/src/test/java/cloud/commandframework/arguments/standard/DurationArgumentTest.java
Show resolved
Hide resolved
cloud-core/src/main/java/cloud/commandframework/arguments/standard/DurationArgument.java
Outdated
Show resolved
Hide resolved
…dard/DurationArgumentSuggestionsTest.java Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
…dard/DurationArgumentTest.java Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
…dard/DurationArgument.java Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
In the video, you typed in But, since you cannot have 88 minutes in an hour, should it accept this? Thoughts? |
88m1s would make more sense than 1d12h88m1s, I agree. But, as long as it's able to parse it, why limit it? Here's a possible scenario where it could be used that way: Maybe I'd type 1h55m and before I press enter, I realize "oh, maybe 10 minutes more would be better", so I'd quickly change it to 1h65m just for the convenience of having to edit less. Or, same scenario if I write something like 80m and then I realize I want to add another day to it |
Am also in favour of keeping this behaviour, I can see someone using something like 100s ^^ |
Hmmm, fair point. |
Also, here's a few features that should be considered. Whether or not they're added is up to you, I guess.
|
Thank you for the detailed comment!
|
At least for ms, I could see some usecase where someone might want greater precision. Eg. a command that starts a task which runs every 500 ms (0.5s) Also, I, personally, would say that colon separated times are more important that ISO dates. Because the ISO dates aren't as friendly to humans as colon separated dates |
This parser being able to parse "incorrect" timeperiods shouldn't be an issue, I don't understand why the parser needs to care if you
These are artificial limitations that don't really provide any value by enforcing them, as you will then need to be able to provide feedback to the user that this was an abitrarily restricted case. Especially for the single-token cases like I don't see the utility in preventing I would keep the parser as is. I don't think the ISO 8601 is appropriate for use here, as that will just be needlessly confusing for end-users in my opinion. |
Hmm, very fair point. I just felt that inputs like But, for single token cases like I'll leave it up to OP to decide if they want to do this.
Also, I'd agree ISO 8601 very much could be needlessly complex. |
We don't want overly opinionated parsers in the core library anyway. Someone could make a future addition to the parser that allows you to toggle stricter behaviour on and off (like the boolean parser's liberal mode), but this should not be the default. |
final String input = inputQueue.peek(); | ||
if (input == null) { | ||
return ArgumentParseResult.failure(new NoInputProvidedException( | ||
DurationArgument.DurationParseException.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be DurationParser.class
?
Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
Co-authored-by: Frank van der Heijden <frank.boekanier@gmail.com>
Expected syntax:
1d12h4m47s
(1 day, 12 hours, 4 minutes, 47 seconds)Tests are included + passing
Example tab completion:
Screen.Recording.2021-12-21.at.3.15.45.PM.mov