Skip to content
Advertisement

Allow any option passed to Symfony CLI

The goal is to allow any options to be passed to symfony CLI, rather than limiting to a defined set of allowed options.

For instance:

php console.php --foo=bar

In this example, foo is an option which is not explicitly allowed by the symfony application.

My console app is proxying to a different application with a number of CLI options. I do not want to have to manually mirror each available option in order to make them available to the symfony application.

Advertisement

Answer

Why not simply creating your own console command (see Symfony doc how to do it) and using its input options or arguments to hand it over?

EDIT

To further clarify what I mean: Do not use the custom options but custom input arguments like:

$this
// ...
->addArgument(
    'options',
    InputArgument::IS_ARRAY | InputArgument::REQUIRED,
    'Please provide options separated by space'
);

Let the user use the command like mycompany:command opt1=val1 opt2=valx (instead of mycompany:command –opt1=val1 –opt2=valx for which you’d have to define opt1 and opt2 indeed)

Read the array, split the values at ‘=’ and hand them over to your 3rd party in the way it’s required. By that opt1 and opt2 is dynamic, one can enter whatever he prefers.

I did not test this approach but I don’t see why this shouldn’t work.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement