clize icon indicating copy to clipboard operation
clize copied to clipboard

Parameter post-converters

Open epsy opened this issue 7 years ago • 0 comments

Currently Clize converts each Python parameter to a Parameter instance by calling a function and using its result:

  • Either the first annotation on that parameter if it is a parameter converter,
  • or the default converter

This makes it impossible to use parameters.multi with parameters.one_of, for instance. This is counter-intuitive and also quite unfortunate.

To fix this, the parameter converter should collect callables from the annotations designated as "post-converters". Once the parameter converter has completed creating a Parameter instance, it should post-process this parameter with each post-converter in order. Each post converters does some changes and returns a Parameter instance, much like decorators.

Example post-converters:

  • parameter.one_of, parameter.mapped, (both already existing as parameter converters)
  • argument_decorator, (already existing as parameter converter)
  • Something to change the name of the value in the help (argparse calls it metavar)
  • UNDOCUMENTED and LAST_OPTION could be refactored as post-converters.

The documentation will need additional clarification on the roles of parameter converters, post-converters and value converters, possibly with a drawing :)

epsy avatar Apr 28 '17 06:04 epsy