Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Open Question: Why is greedy not part of the command context? #373

bergerkiller started this conversation in General
Open Question: Why is greedy not part of the command context? #373
Dec 9, 2020 * 0 comments
Return to top
Discussion options

bergerkiller
Dec 9, 2020

I'm starting to run into a situation where I would like to use @greedy in custom argument parsers. I find that greedy is instead deeply rooted in the standard parsers, and you need to pass some properties to the ArgumentParser object you supply.

In other words, to simply accept an argument with spaces in it, I need to change the argument parser itself, how it is registered, and I'm not sure if what I want even works properly.

Why isn't there a isGreedy() property on the CommandContext itself? Then parsers can check if its greedy and if so, consume the entire queue as part of parsing, and otherwise, consume only one element. This would greatly simplify this api.

My current use case involves double values with units. For example, users can specify:

/command 0.5m/s
/command 20km/h

But there's no reason why they shouldn't be able to:

/command 20 mi/h
/command 20.5 mph

I see no real reason why accepting input with spaces in them should be so strict. Even nicer would be @greedy / setGreedy() squashing the inputs into one separated by spaces, so argument parsers don't even have to take greedy into account.

P.s. I might have trouble with this because of #139

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
General
Labels
question Further information is requested
1 participant
Converted from issue

This discussion was converted from issue #161 on June 09, 2022 03:35.