@@ -7,33 +7,59 @@ const log = debug('cli:block')
7
7
log . error = debug ( 'cli:block:error' )
8
8
9
9
module . exports = {
10
- command : 'get <ref >' ,
10
+ command : 'get <cid path >' ,
11
11
12
- describe : 'Get a dag node from ipfs.' ,
12
+ describe : 'Get a dag node or value from ipfs.' ,
13
13
14
- builder : { } ,
14
+ builder : {
15
+ 'local-resolve' : {
16
+ type : 'boolean' ,
17
+ default : false
18
+ }
19
+ } ,
15
20
16
21
handler ( argv ) {
17
22
utils . getIPFS ( ( err , ipfs ) => {
18
23
if ( err ) {
19
24
throw err
20
25
}
21
26
22
- const refParts = argv . ref . split ( '/' )
27
+ const refParts = argv . cidpath . split ( '/' )
23
28
const cidString = refParts [ 0 ]
24
29
const path = refParts . slice ( 1 ) . join ( '/' )
25
30
const cid = new CID ( cidString )
26
31
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 ) => {
28
37
if ( err ) {
29
38
throw err
30
39
}
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' )
36
44
}
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 )
37
63
} )
38
64
} )
39
65
}
0 commit comments