Decent merge customizer

This commit is contained in:
Bryan Ashby
2020-06-10 19:15:49 -06:00
parent 4237f78938
commit 56472c80a8
3 changed files with 260 additions and 2 deletions

View File

@@ -22,8 +22,28 @@ class Config extends ConfigLoader {
}
static create(basePath, options, cb) {
options.mergeCustomizer = (objValue, srcValue, key, object, source, stack) => {
console.log(key);
const replacePaths = [
'loginServers.ssh.algorithms.kex',
'loginServers.ssh.algorithms.cipher',
'loginServers.ssh.algorithms.hmac',
'loginServers.ssh.algorithms.compress',
];
const replaceKeys = [
'args', 'sendArgs', 'recvArgs', 'recvArgsNonBatch',
];
options.defaultConfig = DefaultConfig();
options.defaultsCustomizer = (defaultVal, configVal, key, path) => {
if (Array.isArray(defaultVal) && Array.isArray(configVal)) {
if (replacePaths.includes(path) || replaceKeys.includes(key)) {
// full replacement using user config value
return configVal;
} else {
// merge user config & default config; keep only unique
_.uniq(defaultVal.concat(configVal));
}
}
};
return ConfigLoader.create(basePath, options, cb);