Support for arbitrary command line arguments
Closed this issue · 2 comments
Description
When using command lines, it is common to specify any number of parameters required rather than just a fixed number. This makes scripting for arbitrary numbers of files easier and faster, by generally requiring less invocations of a given program, saving on start-up time. Most people will be familiar with using xargs and the like for this.
Mako console commands currently do not support this, since all arguments need to be named $argN
and will only ever receive that particular argument. func_get_args
is of no help here either, since the container only injects requested parameters.
I see two ways of implementing this feature, each with their own issues, and both probably requiring some changes to the DI resolver.
Introduce a $args
argument
This will add support for a $args
argument, which would contain all arguments that are not already eaten by some other $argN
argument. This argument could be anywhere in the specification, since the arguments can be resolved out of order, thus not imposing a particular argument order in the Command class.
Support variadic arguments
Instead of introducing a magic argument, we can make use of the features that PHP introduced for this. We can use ReflectionParameter::isVariadic
to check whether the last $argN
is variadic, and then add any remaining arguments to it. I'm not sure whether or not you want to enforce a particular variable name for this.
I somewhat prefer the latter, since it is more in line with what it actually is. Either way, this would be a nice-to-have.
Isn't it possible to use $this->input-> getArguments()
instead of injecting the parameters? Or maybe I'm misunderstanding something.