Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit b0acd08

Browse files
authored
Merge pull request #37 from ipfs/refactor/getIpfs
[WIP] refactor: use getIpfs not ipfs from argv
2 parents a657d7d + d3ff1cb commit b0acd08

File tree

9 files changed

+51
-36
lines changed

9 files changed

+51
-36
lines changed

src/cli/cp.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,21 @@ module.exports = {
4040
let {
4141
source,
4242
dest,
43-
ipfs,
43+
getIpfs,
4444
parents,
4545
format,
4646
hashAlg,
4747
shardSplitThreshold
4848
} = argv
4949

50-
argv.resolve(
51-
ipfs.files.cp(source, dest, {
50+
argv.resolve((async () => {
51+
const ipfs = await getIpfs()
52+
return ipfs.files.cp(source, dest, {
5253
parents,
5354
format,
5455
hashAlg,
5556
shardSplitThreshold
5657
})
57-
)
58+
})())
5859
}
5960
}

src/cli/flush.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ module.exports = {
1414
handler (argv) {
1515
let {
1616
path,
17-
ipfs
17+
getIpfs
1818
} = argv
1919

20-
argv.resolve(
21-
ipfs.files.flush(path || FILE_SEPARATOR, {})
22-
)
20+
argv.resolve((async () => {
21+
const ipfs = await getIpfs()
22+
return ipfs.files.flush(path || FILE_SEPARATOR, {})
23+
})())
2324
}
2425
}

src/cli/ls.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ module.exports = {
4040
handler (argv) {
4141
let {
4242
path,
43-
ipfs,
43+
getIpfs,
4444
long,
4545
sort,
4646
cidBase
4747
} = argv
4848

49-
argv.resolve(
50-
new Promise((resolve, reject) => {
49+
argv.resolve((async () => {
50+
const ipfs = await getIpfs()
51+
return new Promise((resolve, reject) => {
5152
if (sort) {
5253
ipfs.files.ls(path || FILE_SEPARATOR, {
5354
long,
@@ -98,6 +99,6 @@ module.exports = {
9899
})
99100
)
100101
})
101-
)
102+
})())
102103
}
103104
}

src/cli/mkdir.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,24 @@ module.exports = {
4444
handler (argv) {
4545
let {
4646
path,
47-
ipfs,
47+
getIpfs,
4848
parents,
4949
cidVersion,
5050
hashAlg,
5151
flush,
5252
shardSplitThreshold
5353
} = argv
5454

55-
argv.resolve(
56-
ipfs.files.mkdir(path, {
55+
argv.resolve((async () => {
56+
const ipfs = await getIpfs()
57+
58+
return ipfs.files.mkdir(path, {
5759
parents,
5860
cidVersion,
5961
hashAlg,
6062
flush,
6163
shardSplitThreshold
6264
})
63-
)
65+
})())
6466
}
6567
}

src/cli/mv.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ module.exports = {
3535
let {
3636
source,
3737
dest,
38-
ipfs,
38+
getIpfs,
3939
parents,
4040
recursive,
4141
shardSplitThreshold
4242
} = argv
4343

44-
argv.resolve(
45-
ipfs.files.mv(source, dest, {
44+
argv.resolve((async () => {
45+
const ipfs = await getIpfs()
46+
47+
return ipfs.files.mv(source, dest, {
4648
parents,
4749
recursive,
4850
shardSplitThreshold
4951
})
50-
)
52+
})())
5153
}
5254
}

src/cli/read.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ module.exports = {
2828
handler (argv) {
2929
let {
3030
path,
31-
ipfs,
31+
getIpfs,
3232
offset,
3333
length
3434
} = argv
3535

36-
argv.resolve(
37-
new Promise((resolve, reject) => {
36+
argv.resolve((async () => {
37+
const ipfs = await getIpfs()
38+
39+
return new Promise((resolve, reject) => {
3840
pull(
3941
ipfs.files.readPullStream(path, {
4042
offset,
@@ -52,6 +54,6 @@ module.exports = {
5254
})
5355
)
5456
})
55-
)
57+
})())
5658
}
5759
}

src/cli/rm.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ module.exports = {
2222
handler (argv) {
2323
let {
2424
path,
25-
ipfs,
25+
getIpfs,
2626
recursive
2727
} = argv
2828

29-
argv.resolve(
30-
ipfs.files.rm(path, {
29+
argv.resolve((async () => {
30+
const ipfs = await getIpfs()
31+
32+
return ipfs.files.rm(path, {
3133
recursive
3234
})
33-
)
35+
})())
3436
}
3537
}

src/cli/stat.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ Type: <type>`,
5151
handler (argv) {
5252
let {
5353
path,
54-
ipfs,
54+
getIpfs,
5555
format,
5656
hash,
5757
size,
5858
withLocal
5959
} = argv
6060

61-
argv.resolve(
62-
ipfs.files.stat(path, {
61+
argv.resolve((async () => {
62+
const ipfs = await getIpfs()
63+
64+
return ipfs.files.stat(path, {
6365
withLocal
6466
})
6567
.then((stats) => {
@@ -79,6 +81,6 @@ Type: <type>`,
7981
.replace('<type>', stats.type)
8082
)
8183
})
82-
)
84+
})())
8385
}
8486
}

src/cli/write.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module.exports = {
8989
handler (argv) {
9090
let {
9191
path,
92-
ipfs,
92+
getIpfs,
9393
offset,
9494
length,
9595
create,
@@ -106,8 +106,10 @@ module.exports = {
106106
shardSplitThreshold
107107
} = argv
108108

109-
argv.resolve(
110-
ipfs.files.write(path, process.stdin, {
109+
argv.resolve((async () => {
110+
const ipfs = await getIpfs()
111+
112+
return ipfs.files.write(path, process.stdin, {
111113
offset,
112114
length,
113115
create,
@@ -123,6 +125,6 @@ module.exports = {
123125
flush,
124126
shardSplitThreshold
125127
})
126-
)
128+
})())
127129
}
128130
}

0 commit comments

Comments
 (0)