diff --git a/lib/config/cli.js b/lib/config/cli.js index 77b42d9490b21bda8ac57942557dbdd5890dad47..2446d0186893c4626336a7ded262ec055b966555 100644 --- a/lib/config/cli.js +++ b/lib/config/cli.js @@ -22,8 +22,16 @@ function getConfig(argv) { const coersions = { boolean: val => val === 'true', - list: val => - val === '[]' || val === '' ? [] : val.split(',').map(el => el.trim()), + list: val => { + if (val === '') { + return []; + } + try { + return JSON.parse(val); + } catch (err) { + return val.split(',').map(el => el.trim()); + } + }, string: val => val, integer: parseInt, }; diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 75dec33b5eb659c15d8b27e06731a30ac4099aff..79c225e732d5855b2437b2cbf30250aec03c3d58 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -1161,6 +1161,7 @@ const options = [ description: 'Endpoint configuration for credentials', type: 'list', stage: 'repository', + cli: true, mergeable: true, }, ]; diff --git a/test/config/cli.spec.js b/test/config/cli.spec.js index f9a08e36ae60501f369db2e5843c9afc88c5a2b0..b5970bf019ed2e6be21de8539aee76db73b5a8e0 100644 --- a/test/config/cli.spec.js +++ b/test/config/cli.spec.js @@ -65,5 +65,32 @@ describe('config/cli', () => { argv.push('bar'); cli.getConfig(argv).should.eql({ repositories: ['foo', 'bar'] }); }); + it('parses json lists correctly', () => { + argv.push( + `--endpoints=[{"host":"docker.io","platform":"docker","username":"user","password":"password"}]` + ); + cli.getConfig(argv).should.deep.equal({ + endpoints: [ + { + host: 'docker.io', + platform: 'docker', + username: 'user', + password: 'password', + }, + ], + }); + }); + it('parses [] correctly as empty list of endpoints', () => { + argv.push(`--endpoints=[]`); + cli.getConfig(argv).should.eql({ + endpoints: [], + }); + }); + it('parses an empty string correctly as empty list of endpoints', () => { + argv.push(`--endpoints=`); + cli.getConfig(argv).should.eql({ + endpoints: [], + }); + }); }); });