swarrot / SwarrotBundle

A symfony bundle for swarrot integration
MIT License
89 stars 59 forks source link

Allow processors' options to be override by command line arguments #112

Closed raphael-trzpit closed 3 years ago

raphael-trzpit commented 7 years ago

It is possible to override defaults options with command line arguments. But when you add 'extras' to change the default value for your consumer, this disable the command line arguments override, because the default extras are merged first. This change aims to keep the override even if you set extra options in your config.

raphael-trzpit commented 7 years ago

i'm gonna do it today or tomorrow when i got some time :)

raphael-trzpit commented 7 years ago

tests done, ping @olaurendeau :)

odolbeau commented 7 years ago

Hi!

I tooks me a lot of time to understand your problem. :)

Let's be clear on how it works today. First of all here is the priority we want to respect: command options > extra config > default

Let's take a concrete example with the MaxExecutionTimeProcessor which have a max_execution_time configurable option. In this example the "default value" we talk about is the value displayed when you print the help for the command and the "actual value" is what you'll have in your processor in the $options['max_execution_time']..

This is the latest use case which don't work in your case if I understand well.

Here is the config I used to check that everything is fine:

swarrot:
    consumers:
        test:
            processor: "AppBundle\\Processor\\DumpConfigProcessor"
            middleware_stack:
                - configurator: swarrot.processor.max_execution_time
                  extras:
                      max_execution_time: 100

Here is the config you (probably) used:

swarrot:
    consumers:
        test:
            processor: "AppBundle\\Processor\\DumpConfigProcessor"
            middleware_stack:
                - configurator: swarrot.processor.max_execution_time
            extras:
                max_execution_time: 100

I added extras for the configurator, you added it on the consumer directly. It took me some time to find this problem... even if I already encountered it with a teammate. I'm embarrassed, I didn't take the time to correct this...

Anyway, what should we do now? IMO it should not be possible to add an invalid configuration key somewhere. Right now:

Here is what I propose:

raphael-trzpit commented 6 years ago

hey, i agree the 3rd case is hard : options can be added to both the extras of the consumer and the extras of the processor (because they are merged). Currently the extras of the processor are merged first, so any configuration done in the processorConfigurators doesn't even matter (vs the processor).

I made a PR for the command tests :)