Search code examples
symfonyconsolesymfony-components

Make a symfony/console command accept key=value arguments


I want to use the Symfony console component to make a command like this:

app/console config:set someConfigName=someValue anotherConfig=anotherValue

I found this question: Variable number of options for symfony/console component

But it seems unmaintainable to hack ArgvInput and pass it to $app->run(). I'd have to also hack ArrayInput and StringInput, in order to do unit testing, and I'm not sure I'd be able to inject them in the test.

Any help appreciated.


Solution

  • Feel kind of silly about this. :-)

    Arguments are always a space-delimited string, and key=value looks like a space-delimited string. Explode the string with = as the delimiter, and you have the key and the value.