diff --git a/lib/config/cli.js b/lib/config/cli.js index 44570d4808a4abd472251e26affe126ca29ab145..50da603b4c2dbd20cbbc640be23ca5f6c68fd4a5 100644 --- a/lib/config/cli.js +++ b/lib/config/cli.js @@ -53,6 +53,16 @@ function getConfig(input) { return val.split(',').map(el => el.trim()); } }, + object: val => { + if (val === '') { + return {}; + } + try { + return JSON.parse(val); + } catch (err) { + throw new Error("Invalid JSON value: '" + val + "'"); + } + }, string: val => val, integer: parseInt, }; @@ -81,6 +91,9 @@ function getConfig(input) { ' $ renovate --labels=renovate,dependency --ignore-unstable=false --log-level debug singapore/lint-condo' ); console.log(' $ renovate singapore/lint-condo singapore/package-test'); + console.log( + ` $ renovate singapore/lint-condo --onboarding-config='{"extends":["config:base"]}'` + ); /* eslint-enable no-console */ } diff --git a/lib/config/definitions.js b/lib/config/definitions.js index e8ecdbab11a2efd725e5022f6ab4c9ee4d0bed6c..1c7d1559265419be3e2886b67cc782d7489b3c9a 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -139,7 +139,6 @@ const options = [ default: {}, admin: true, mergeable: true, - cli: false, }, { name: 'includeForks', diff --git a/test/config/cli.spec.js b/test/config/cli.spec.js index e416fd0a76c1ce0bc2d369b0b3c8a783375246c6..ecc60376b58400f7660621c20edff6fc8dbd0af0 100644 --- a/test/config/cli.spec.js +++ b/test/config/cli.spec.js @@ -107,5 +107,31 @@ describe('config/cli', () => { hostRules: [], }); }); + it('parses json object correctly when empty', () => { + argv.push(`--onboarding-config=`); + cli.getConfig(argv).should.deep.equal({ + onboardingConfig: {}, + }); + }); + it('parses json {} object correctly', () => { + argv.push(`--onboarding-config={}`); + cli.getConfig(argv).should.deep.equal({ + onboardingConfig: {}, + }); + }); + it('parses json object correctly', () => { + argv.push(`--onboarding-config={"extends": ["config:base"]}`); + cli.getConfig(argv).should.deep.equal({ + onboardingConfig: { + extends: ['config:base'], + }, + }); + }); + it('throws exception for invalid json object', () => { + argv.push('--onboarding-config=Hello_World'); + expect(() => cli.getConfig(argv)).toThrow( + Error("Invalid JSON value: 'Hello_World'") + ); + }); }); });