@@ -7,33 +7,59 @@ const log = debug('cli:block')
77log . error = debug ( 'cli:block:error' )
88
99module . exports = {
10- command : 'get <ref >' ,
10+ command : 'get <cid path >' ,
1111
12- describe : 'Get a dag node from ipfs.' ,
12+ describe : 'Get a dag node or value from ipfs.' ,
1313
14- builder : { } ,
14+ builder : {
15+ 'local-resolve' : {
16+ type : 'boolean' ,
17+ default : false
18+ }
19+ } ,
1520
1621 handler ( argv ) {
1722 utils . getIPFS ( ( err , ipfs ) => {
1823 if ( err ) {
1924 throw err
2025 }
2126
22- const refParts = argv . ref . split ( '/' )
27+ const refParts = argv . cidpath . split ( '/' )
2328 const cidString = refParts [ 0 ]
2429 const path = refParts . slice ( 1 ) . join ( '/' )
2530 const cid = new CID ( cidString )
2631
27- ipfs . dag . get ( cid , path , ( err , result ) => {
32+ const options = {
33+ localResolve : argv . localResolve
34+ }
35+
36+ ipfs . dag . get ( cid , path , options , ( err , result ) => {
2837 if ( err ) {
2938 throw err
3039 }
31- const obj = result . value
32- if ( Buffer . isBuffer ( obj ) ) {
33- console . log ( '0x' + obj . toString ( 'hex' ) )
34- } else {
35- console . log ( obj )
40+
41+ if ( options . localResolve ) {
42+ console . log ( 'resolving path within the node only' )
43+ console . log ( 'remainder path:' , result . remainderPath || 'n/a' , '\n' )
3644 }
45+
46+ const node = result . value
47+
48+ // TODO we need to find* a way to pretty print objects
49+ // * reads as 'agree in'
50+ if ( node . _json ) {
51+ delete node . _json . multihash
52+ node . _json . data = '0x' + node . _json . data . toString ( 'hex' )
53+ console . log ( node . _json )
54+ return
55+ }
56+
57+ if ( Buffer . isBuffer ( node ) ) {
58+ console . log ( '0x' + node . toString ( 'hex' ) )
59+ return
60+ }
61+
62+ console . log ( node )
3763 } )
3864 } )
3965 }
0 commit comments