Using Clap for entirely the wrong purpose

68 points HammerAPI

Hi,

As the title suggests, I'm using the clap crate for something it's entirely not supposed to be used for. Long story short, I am trying to set up a REPL (which it can be used for, though that's not super important) that parses commands that are multiple words and do not contain flags (-f and --flag).

Here are are some example commands that I would like to parse:

toggle <FEATURE NAME> [ on | off ]

login name <USER NAME> key <digits>

setup [ init | position <POSITION STRING> ]

apply <STRING1> [STRING2 ... STRINGN]

For simple commands, like toggle <FEATURE> [ on | off ] I have been able to get this to work by using some features like ValueEnum. And, for the more complicated commands like setup [ init | position <STRING> ] I have been able to get a mock-up to work by nesting sub commands.

However, what I cannot figure out is how to get clap to parse a command whose argument is a single word. For example, I can parse toggle Debug on just fine. but I can't parse toggle Debug Info on.

I would like to know if anyone has worked with Clap enough to know of a solution to this.