From 235e194fdba64a4ac1c88d73b7ba40535950fc6d Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 24 Oct 2018 12:10:37 +0100 Subject: [PATCH 1/2] feat: add support to pass config in the init cmd --- src/cli/commands/init.js | 11 +++++++---- src/core/components/init.js | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index d7cbf090d1..9ff0cdef6a 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -4,13 +4,15 @@ const utils = require('../utils') const print = utils.print module.exports = { - command: 'init', - + command: 'init [config] [options]', describe: 'Initialize a local IPFS node', - builder (yargs) { return yargs .epilog(utils.ipfsPathHelp) + .positional('config', { + describe: 'Node config, this should JSON and will be merged with the default config. Check https://github.com/ipfs/js-ipfs#optionsconfig', + type: 'string' + }) .option('bits', { type: 'number', alias: 'b', @@ -41,7 +43,8 @@ module.exports = { const node = new IPFS({ repo: new Repo(path), init: false, - start: false + start: false, + config: argv.config }) node.init({ diff --git a/src/core/components/init.js b/src/core/components/init.js index eb91a09979..287d827301 100644 --- a/src/core/components/init.js +++ b/src/core/components/init.js @@ -4,6 +4,7 @@ const peerId = require('peer-id') const waterfall = require('async/waterfall') const parallel = require('async/parallel') const promisify = require('promisify-es6') +const extend = require('deep-extend') const defaultConfig = require('../runtime/config-nodejs.js') const Keychain = require('libp2p-keychain') @@ -50,7 +51,8 @@ module.exports = function init (self) { opts.emptyRepo = opts.emptyRepo || false opts.bits = Number(opts.bits) || 2048 opts.log = opts.log || function () {} - const config = defaultConfig() + + const config = extend(defaultConfig(), self._options.config) let privateKey waterfall([ From ca7677d3a4eca456d585680017db952739fe2845 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 29 Oct 2018 13:59:16 +0000 Subject: [PATCH 2/2] fix: use defaults-deep --- src/core/components/init.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/components/init.js b/src/core/components/init.js index 287d827301..258e8a411a 100644 --- a/src/core/components/init.js +++ b/src/core/components/init.js @@ -4,7 +4,7 @@ const peerId = require('peer-id') const waterfall = require('async/waterfall') const parallel = require('async/parallel') const promisify = require('promisify-es6') -const extend = require('deep-extend') +const defaultsDeep = require('@nodeutils/defaults-deep') const defaultConfig = require('../runtime/config-nodejs.js') const Keychain = require('libp2p-keychain') @@ -52,7 +52,7 @@ module.exports = function init (self) { opts.bits = Number(opts.bits) || 2048 opts.log = opts.log || function () {} - const config = extend(defaultConfig(), self._options.config) + const config = defaultsDeep(self._options.config, defaultConfig()) let privateKey waterfall([