From 0deed26fe726900e884446c72b8dc1af9ade5424 Mon Sep 17 00:00:00 2001 From: Nuno Nogueira Date: Mon, 5 Dec 2016 13:31:33 +0000 Subject: [PATCH] Support Swarm disconnect in CLI. --- src/cli/commands/swarm/disconnect.js | 15 +++++++++++++-- test/cli/test-swarm.js | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/swarm/disconnect.js b/src/cli/commands/swarm/disconnect.js index a28123b796..44df126b1d 100644 --- a/src/cli/commands/swarm/disconnect.js +++ b/src/cli/commands/swarm/disconnect.js @@ -8,16 +8,27 @@ log.error = debug('cli:object:error') module.exports = { command: 'disconnect
', - describe: '', + describe: 'Close connection to a given address', builder: {}, handler (argv) { + if (!utils.isDaemonOn()) { + throw new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.') + } + utils.getIPFS((err, ipfs) => { if (err) { throw err } - // TODO + + ipfs.swarm.disconnect(argv.address, (err, res) => { + if (err) { + throw err + } + + console.log(res.Strings[0]) + }) }) } } diff --git a/test/cli/test-swarm.js b/test/cli/test-swarm.js index d846337024..612c27ca46 100644 --- a/test/cli/test-swarm.js +++ b/test/cli/test-swarm.js @@ -75,5 +75,13 @@ describe('swarm', function () { expect(out).to.have.length.above(0) }) }) + + it('disconnect', () => { + return ipfs('swarm', 'disconnect', nodeAddr).then((out) => { + expect(out).to.be.eql( + `disconnect ${nodeAddr} success` + ) + }) + }) }) })