diff --git a/src/cli/commands/bitswap/unwant.js b/src/cli/commands/bitswap/unwant.js index 840276e9b2..ad5b1460fb 100644 --- a/src/cli/commands/bitswap/unwant.js +++ b/src/cli/commands/bitswap/unwant.js @@ -1,11 +1,25 @@ 'use strict' +const print = require('../../utils').print + module.exports = { command: 'unwant ', - describe: 'Remove a given block from your wantlist.', + describe: 'Removes a given block from your wantlist.', + builder: { + key: { + alias: 'k', + describe: 'Key to remove from your wantlist', + type: 'string' + } + }, handler (argv) { - throw new Error('Not implemented yet') + argv.ipfs.bitswap.unwant(argv.key, (err, res) => { + if (err) { + throw err + } + print(`Key ${argv.key} removed from wantlist`) + }) } } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index da830c6415..ca390c0829 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -46,10 +46,19 @@ exports.stat = (request, reply) => { } exports.unwant = { - // uses common parseKey method that returns a `key` + // uses common parseKey method that assigns a `key` to request.pre.args parseArgs: parseKey, + // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { - reply(boom.badRequest(new Error('Not implemented yet'))) + const key = request.pre.args.key + const ipfs = request.server.app.ipfs + try { + ipfs.bitswap.unwant(key) + } catch(err) { + return reply(boom.badRequest(err)) + } + + reply({ Key: key }) } } diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 6652364f9b..223fc22338 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => { }) }) - // TODO @hacdias fix this with https://github.com/ipfs/js-ipfs/pull/1198 - it.skip('stat', function () { + it('stat', function () { this.timeout(20 * 1000) return ipfs('bitswap stat').then((out) => { @@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => { ].join('\n') + '\n') }) }) + + it('unwant', function () { + return ipfs('bitswap unwant ' + key).then((out) => { + expect(out).to.eql(`Key ${key} removed from wantlist\n`) + }); + }) }))