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` + ) + }) + }) }) })