Skip to content

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

@bergerkiller

Description

@bergerkiller

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions