This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 4 files changed +80
-1
lines changed
4 files changed +80
-1
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ module . exports = {
4
+ command : 'dag' ,
5
+
6
+ description : 'Interact with ipld dag objects.' ,
7
+
8
+ builder ( yargs ) {
9
+ return yargs
10
+ . commandDir ( 'dag' )
11
+ } ,
12
+
13
+ handler ( argv ) {
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const utils = require ( '../../utils' )
4
+ const CID = require ( 'cids' )
5
+ const debug = require ( 'debug' )
6
+ const log = debug ( 'cli:block' )
7
+ log . error = debug ( 'cli:block:error' )
8
+
9
+ module . exports = {
10
+ command : 'get <ref>' ,
11
+
12
+ describe : 'Get a dag node from ipfs.' ,
13
+
14
+ builder : { } ,
15
+
16
+ handler ( argv ) {
17
+ utils . getIPFS ( ( err , ipfs ) => {
18
+ if ( err ) {
19
+ throw err
20
+ }
21
+
22
+ const refParts = argv . ref . split ( '/' )
23
+ const cidString = refParts [ 0 ]
24
+ const pathString = refParts . slice ( 1 ) . join ( '/' )
25
+ const cid = new CID ( cidString )
26
+
27
+ let lookupFn
28
+ if ( pathString ) {
29
+ lookupFn = ( ) => ipfs . dag . resolve ( cid , pathString )
30
+ } else {
31
+ lookupFn = ( ) => ipfs . dag . get ( cid )
32
+ }
33
+
34
+ lookupFn ( )
35
+ . then ( ( obj ) => {
36
+ console . log ( obj )
37
+ } )
38
+ . catch ( ( err ) => {
39
+ console . error ( err )
40
+ } )
41
+ } )
42
+ }
43
+ }
Original file line number Diff line number Diff line change 4
4
const expect = require ( 'chai' ) . expect
5
5
const runOnAndOff = require ( '../utils/on-and-off' )
6
6
7
- const commandCount = 61
7
+ const commandCount = 63
8
8
9
9
describe ( 'commands' , ( ) => runOnAndOff ( ( thing ) => {
10
10
let ipfs
Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const expect = require ( 'chai' ) . expect
5
+ const runOnAndOff = require ( '../utils/on-and-off' )
6
+
7
+ describe ( 'dag' , ( ) => runOnAndOff ( ( thing ) => {
8
+ let ipfs
9
+
10
+ before ( ( ) => {
11
+ ipfs = thing . ipfs
12
+ } )
13
+
14
+ it ( 'get' , ( ) => {
15
+ return ipfs ( 'dag get z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS/parentHash' ) . then ( ( out ) => {
16
+ let expectHash = new Buffer ( 'c8c0a17305adea9bbb4b98a52d44f0c1478f5c48fc4b64739ee805242501b256' , 'hex' )
17
+ expect ( out ) . to . be . eql ( expectHash )
18
+ } )
19
+ } )
20
+
21
+ } ) )
You can’t perform that action at this time.
0 commit comments