From b90ba760e03da205e05f70e6344d9fc0c2ff7431 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 9 Feb 2017 23:02:11 -0800 Subject: [PATCH] fix: tidy dag cli up --- src/cli/commands/dag/get.js | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/cli/commands/dag/get.js b/src/cli/commands/dag/get.js index 7f8986508b..4755f10cfb 100644 --- a/src/cli/commands/dag/get.js +++ b/src/cli/commands/dag/get.js @@ -7,11 +7,16 @@ const log = debug('cli:block') log.error = debug('cli:block:error') module.exports = { - command: 'get ', + command: 'get ', - describe: 'Get a dag node from ipfs.', + describe: 'Get a dag node or value from ipfs.', - builder: {}, + builder: { + 'local-resolve': { + type: 'boolean', + default: false + } + }, handler (argv) { utils.getIPFS((err, ipfs) => { @@ -19,21 +24,42 @@ module.exports = { throw err } - const refParts = argv.ref.split('/') + const refParts = argv.cidpath.split('/') const cidString = refParts[0] const path = refParts.slice(1).join('/') const cid = new CID(cidString) - ipfs.dag.get(cid, path, (err, result) => { + const options = { + localResolve: argv.localResolve + } + + ipfs.dag.get(cid, path, options, (err, result) => { if (err) { throw err } - const obj = result.value - if (Buffer.isBuffer(obj)) { - console.log('0x' + obj.toString('hex')) - } else { - console.log(obj) + + if (options.localResolve) { + console.log('resolving path within the node only') + console.log('remainder path:', result.remainderPath || 'n/a', '\n') } + + const node = result.value + + // TODO we need to find* a way to pretty print objects + // * reads as 'agree in' + if (node._json) { + delete node._json.multihash + node._json.data = '0x' + node._json.data.toString('hex') + console.log(node._json) + return + } + + if (Buffer.isBuffer(node)) { + console.log('0x' + node.toString('hex')) + return + } + + console.log(node) }) }) }