Add option to merge formatters via file and via CLI.
Closed this issue ยท 3 comments
Hello! ๐
We have a use case where we'd like to dynamically add --format json --out tmp/ <some-file>.json flags to our CI-side rspec runs. The issue we have is that we've got a few custom formatters specified in a file called .rspec.ci, which we load up front using the --options flag. These formatters are then removed when the CLI flags are provided, since CLI-provided formatters take absolute preference over file-provided in the organize_options method.
I'm not particularly stoked about requesting to add an additional configuration option to allow these formatters to be merged instead of over-written, but I'm even less stoked to request we change the default behaviour, since someone will inevitably depend on this behaviour.
The alternative option would be to move all of the custom formatters into the CLI as options, but that feels a bit less ergonomic WRT using the options files.
Any thoughts most welcome!
How it will be possible to override those options from the CLI?
My proposal would be to add a new CLI flag called something like --merge-formatters which would cause :formatter to be included in the organize_options method.
Something like:
mergeable_keys = [:libs, :requires]
mergeable_keys << :formatter if merge_formatters_flag_set
@options = @options.inject(:libs => [], :requires => []) do |hash, opts|
hash.merge(opts) do |key, oldval, newval|
mergeable_keys.include?(key) ? oldval + newval : newval
end
endIt makes sense to me to add it as an additional flag because it would be changing behaviour that someone else likely depends on.
๐ I'm going to close this as not planned because I'd rather not have additional complexity here; I would suggest that your CI should either define all the formatters for a run in its file, or if you need dynamic configuration you do so in the spec_helper (or another CI ruby file).