Message250675
> With my type function, the string input is converted to an enum object and that is stored in the Namespace. You can't be any more direct than that.
Yes I know, but in that case it's missing the autogenerated help message with the possible choices.
I know I can generate it manually, it just does not feel right for doing something so simple. IMO the goal of argparse is to unload the burden of checking/validating parameters manually, generating help messages with default/possible values, etc.
Your solution with a dictionnary is similar to what I currently use and wrote in my example, with the added drawback that the keys are randomly ordered in the help message, unless I use OrderedDict (one more import and more boilerplate code).
Each approach has its drawbacks, unless you write some additional code to workaround each limitation.
In a perfect world, argparse would:
* only show to the user the enum names, and use it in help/error messages, possible choice set, etc.
* after parsing, set the real enum value in the namespace
* and most importantly: to do that, don't require more code than just passing the enum |
|
Date |
User |
Action |
Args |
2015-09-14 16:29:03 | desbma | set | recipients:
+ desbma, barry, paul.j3 |
2015-09-14 16:29:03 | desbma | set | messageid: <1442248143.45.0.912463017159.issue25061@psf.upfronthosting.co.za> |
2015-09-14 16:29:03 | desbma | link | issue25061 messages |
2015-09-14 16:29:02 | desbma | create | |
|