Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a003e2b

Browse files
authored
Merge pull request #640 from nunofmn/swarm-disconnect-cli
Add swarm disconnect cli
2 parents 9333990 + 0deed26 commit a003e2b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/cli/commands/swarm/disconnect.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@ log.error = debug('cli:object:error')
88
module.exports = {
99
command: 'disconnect <address>',
1010

11-
describe: '',
11+
describe: 'Close connection to a given address',
1212

1313
builder: {},
1414

1515
handler (argv) {
16+
if (!utils.isDaemonOn()) {
17+
throw new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
18+
}
19+
1620
utils.getIPFS((err, ipfs) => {
1721
if (err) {
1822
throw err
1923
}
20-
// TODO
24+
25+
ipfs.swarm.disconnect(argv.address, (err, res) => {
26+
if (err) {
27+
throw err
28+
}
29+
30+
console.log(res.Strings[0])
31+
})
2132
})
2233
}
2334
}

test/cli/test-swarm.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,13 @@ describe('swarm', function () {
7575
expect(out).to.have.length.above(0)
7676
})
7777
})
78+
79+
it('disconnect', () => {
80+
return ipfs('swarm', 'disconnect', nodeAddr).then((out) => {
81+
expect(out).to.be.eql(
82+
`disconnect ${nodeAddr} success`
83+
)
84+
})
85+
})
7886
})
7987
})

0 commit comments

Comments
 (0)