From 3f4e464e2ba92f444b540015a0026bbcc1a91e66 Mon Sep 17 00:00:00 2001
From: jgarec <jgarec@users.noreply.github.com>
Date: Tue, 11 Jun 2019 06:19:05 +0200
Subject: [PATCH] feat(cli): enable onboarding-config cli option (#3910)

---
 lib/config/cli.js         | 13 +++++++++++++
 lib/config/definitions.js |  1 -
 test/config/cli.spec.js   | 26 ++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/lib/config/cli.js b/lib/config/cli.js
index 44570d4808..50da603b4c 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 e8ecdbab11..1c7d155926 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 e416fd0a76..ecc60376b5 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'")
+      );
+    });
   });
 });
-- 
GitLab