mpeterv / argparse

Feature-rich command line parser for Lua
MIT License
251 stars 43 forks source link

Multi-argument options and conversion #14

Closed NicolBolas closed 6 years ago

NicolBolas commented 6 years ago

This issue derives from this Stack Overflow question. In that question, the user creates an option that takes two arguments. He can apply a convert operation, but it only applies to the option; it isn't argument-specific. So he can't convert two arguments in different ways.

The workaround provided by the answer is to use a hidden index and a sequence of functions to allow the single function to behave differently for different arguments. But it only works "by accident"; that is, it only works so long as argparse converts arguments in-order and only once per argument.

It might be better to have a more robust solution to this problem. Perhaps convert could take multiple functions, and if you provide such, it applies them to the arguments in-order.

mpeterv commented 6 years ago

I agree, if an array of functions is passed to convert it should apply them to corresponding arguments. Similar idea is used with argname property already.

mpeterv commented 6 years ago

Implemented on master branch.