Selecting multiple configs from a Config Group
Problemβ
In some scenarios, one may need to select multiple configs from the same Config Group.
Solutionβ
Use a list of config names as the value of the config group in the Defaults List or in the command line.
Exampleβ
In this example, we configure a server. The server can host multiple websites at the same time.
βββ config.yaml
βββ server
βββ apache.yaml
βββ site
βββ amazon.yaml
βββ fb.yaml
βββ google.yaml
defaults:
- server/apache
defaults:
- site:
- fb
- google
host: localhost
port: 443
amazon:
domain: amazon.com
fb:
domain: facebook.com
google:
domain: google.com
Output:
server:
site:
fb:
domain: facebook.com
google:
domain: google.com
host: localhost
port: 443
Override the selected sites from the command line by passing a list. e.g:
server:
site:
google:
domain: google.com
amazon:
domain: amazon.com
host: localhost
port: 443
Overriding packagesβ
You can relocate the package of all the configs in the list. e.g:
defaults:
- site@https:
- fb
- google
server:
https:
fb:
domain: facebook.com
google:
domain: google.com
When overriding the selected configs of config groups with overridden packages you need to use the package. e.g:
server:
https:
amazon:
domain: amazon.com
host: localhost
port: 443
Implementation considerationsβ
A nested list in the Defaults List is interpreted as a list of non-overridable configs:
defaults:
- site:
- fb
- google
defaults:
- site/fb
- site/google
All default package for all the configs in server/site
is server.site
.
This example uses an explicit nesting level inside each of the website configs to prevent them stepping over one another:
amazon:
...