commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Support for default verb?

Open alexreg opened this issue 7 years ago • 7 comments

Is there any support for some sort of "default" verb? That is, a verb that gets executed when no verb is actually specified. Perhaps an existing verb can be marked as default, even?

alexreg avatar Oct 16 '17 17:10 alexreg

Furthermore, is it possible to have global options while still having a verb?

alexreg avatar Oct 16 '17 17:10 alexreg

This is a duplicate of #490. Unfortunately, no it isn't possible. With the way verbs work in the current version (e.g. Parse<VerbA, VerbB>(args)) I'm having a hard time thinking of a way to add a default verb and global options.

nemec avatar Oct 16 '17 17:10 nemec

Thanks for the quick reply, @nemec. What about a simple IsDefault property of the Verb attribute. The name of the verb should also be optional in this case. As for global options, what about a special Options generic argument that inherits from a (dummy) GlobalOptions class, or something similar?

Update: Actually, quite a nice solution that already works is simply inheriting from a GlobalOptions class!

alexreg avatar Oct 16 '17 18:10 alexreg

I'm currently trying to come up with a workaround for this, but I can't get the NoVerbSelectedError, nor the BadVerbSelectedError. It just runs my (one and only) options handler instead. Using the latest beta here. Any known issue with that right now?

alexreg avatar Oct 16 '17 18:10 alexreg

Update: it seems I have to specify at least two options types to ParseArguments for these errors to kick in! I see why, though perhaps this should be documented.

alexreg avatar Oct 16 '17 20:10 alexreg

You're right - it is not obvious that one generic argument is interpreted as an Options class but multiple are considered Verbs.

nemec avatar Oct 17 '17 00:10 nemec

Just to clarify, is there a workaround by using GlobalOptions?

TheFanatr avatar Oct 21 '17 07:10 TheFanatr