Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit cb4f7ae

Browse files
authored
refactor: remove yargs-promise from cli (#2795)
Also improves bin.js, parser.js and utils.js to support it and future refactor of the tests.
1 parent c6072a0 commit cb4f7ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1299
-1740
lines changed

packages/ipfs-mfs/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
"sinon": "^8.0.4",
5656
"stream-to-promise": "^2.2.0",
5757
"temp-write": "^4.0.0",
58-
"yargs": "^15.0.2",
59-
"yargs-promise": "^1.1.0"
58+
"yargs": "^15.1.0"
6059
},
6160
"dependencies": {
6261
"@hapi/boom": "^7.4.3",

packages/ipfs-mfs/src/cli/chmod.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,20 @@ module.exports = {
4949

5050
handler (argv) {
5151
const {
52+
ctx: { ipfs },
5253
path,
5354
mode,
54-
getIpfs,
5555
recursive,
5656
hashAlg,
5757
flush,
5858
shardSplitThreshold
5959
} = argv
6060

61-
argv.resolve((async () => {
62-
const ipfs = await getIpfs()
63-
64-
return ipfs.files.chmod(path, mode, {
65-
recursive,
66-
hashAlg,
67-
flush,
68-
shardSplitThreshold
69-
})
70-
})())
61+
return ipfs.files.chmod(path, mode, {
62+
recursive,
63+
hashAlg,
64+
flush,
65+
shardSplitThreshold
66+
})
7167
}
7268
}

packages/ipfs-mfs/src/cli/cp.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,20 @@ module.exports = {
3939

4040
handler (argv) {
4141
const {
42+
ctx: { ipfs },
4243
source,
4344
dest,
44-
getIpfs,
4545
parents,
4646
flush,
4747
hashAlg,
4848
shardSplitThreshold
4949
} = argv
5050

51-
argv.resolve((async () => {
52-
const ipfs = await getIpfs()
53-
return ipfs.files.cp(source, dest, {
54-
parents,
55-
flush,
56-
hashAlg,
57-
shardSplitThreshold
58-
})
59-
})())
51+
return ipfs.files.cp(source, dest, {
52+
parents,
53+
flush,
54+
hashAlg,
55+
shardSplitThreshold
56+
})
6057
}
6158
}

packages/ipfs-mfs/src/cli/flush.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,21 @@ module.exports = {
1515
}
1616
},
1717

18-
handler (argv) {
18+
async handler (argv) {
1919
const {
20+
ctx: { ipfs, print },
2021
path,
21-
getIpfs,
22-
cidBase,
23-
print
22+
cidBase
2423
} = argv
2524

26-
argv.resolve((async () => {
27-
const ipfs = await getIpfs()
28-
let cid = await ipfs.files.flush(path || FILE_SEPARATOR, {})
25+
let cid = await ipfs.files.flush(path || FILE_SEPARATOR, {})
2926

30-
if (cidBase && cidBase !== 'base58btc' && cid.version === 0) {
31-
cid = cid.toV1()
32-
}
27+
if (cidBase && cidBase !== 'base58btc' && cid.version === 0) {
28+
cid = cid.toV1()
29+
}
3330

34-
print(JSON.stringify({
35-
Cid: cid.toString(cidBase)
36-
}))
37-
})())
31+
print(JSON.stringify({
32+
Cid: cid.toString(cidBase)
33+
}))
3834
}
3935
}

packages/ipfs-mfs/src/cli/ls.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,37 @@ module.exports = {
3535
}
3636
},
3737

38-
handler (argv) {
38+
async handler (argv) {
3939
const {
40+
ctx: { ipfs, print },
4041
path,
41-
getIpfs,
4242
long,
4343
sort,
44-
cidBase,
45-
print
44+
cidBase
4645
} = argv
4746

48-
argv.resolve((async () => {
49-
const ipfs = await getIpfs()
50-
51-
const printListing = file => {
52-
if (long) {
53-
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.cid.toString(cidBase)}\t${file.size}`)
54-
} else {
55-
print(file.name)
56-
}
47+
const printListing = file => {
48+
if (long) {
49+
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.cid.toString(cidBase)}\t${file.size}`)
50+
} else {
51+
print(file.name)
5752
}
53+
}
5854

59-
// https://github.com/ipfs/go-ipfs/issues/5181
60-
if (sort) {
61-
let files = await all(ipfs.files.ls(path || FILE_SEPARATOR))
55+
// https://github.com/ipfs/go-ipfs/issues/5181
56+
if (sort) {
57+
let files = await all(ipfs.files.ls(path || FILE_SEPARATOR))
6258

63-
files = files.sort((a, b) => {
64-
return a.name.localeCompare(b.name)
65-
})
59+
files = files.sort((a, b) => {
60+
return a.name.localeCompare(b.name)
61+
})
6662

67-
files.forEach(printListing)
68-
return
69-
}
63+
files.forEach(printListing)
64+
return
65+
}
7066

71-
for await (const file of ipfs.files.ls(path || FILE_SEPARATOR)) {
72-
printListing(file)
73-
}
74-
})())
67+
for await (const file of ipfs.files.ls(path || FILE_SEPARATOR)) {
68+
printListing(file)
69+
}
7570
}
7671
}

packages/ipfs-mfs/src/cli/mkdir.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ module.exports = {
5757

5858
handler (argv) {
5959
const {
60+
ctx: { ipfs },
6061
path,
61-
getIpfs,
6262
parents,
6363
cidVersion,
6464
hashAlg,
@@ -68,18 +68,14 @@ module.exports = {
6868
mtime
6969
} = argv
7070

71-
argv.resolve((async () => {
72-
const ipfs = await getIpfs()
73-
74-
return ipfs.files.mkdir(path, {
75-
parents,
76-
cidVersion,
77-
hashAlg,
78-
flush,
79-
shardSplitThreshold,
80-
mode,
81-
mtime
82-
})
83-
})())
71+
return ipfs.files.mkdir(path, {
72+
parents,
73+
cidVersion,
74+
hashAlg,
75+
flush,
76+
shardSplitThreshold,
77+
mode,
78+
mtime
79+
})
8480
}
8581
}

packages/ipfs-mfs/src/cli/mv.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ module.exports = {
5252

5353
handler (argv) {
5454
const {
55+
ctx: { ipfs },
5556
source,
5657
dest,
57-
getIpfs,
5858
parents,
5959
recursive,
6060
cidVersion,
@@ -63,17 +63,13 @@ module.exports = {
6363
shardSplitThreshold
6464
} = argv
6565

66-
argv.resolve((async () => {
67-
const ipfs = await getIpfs()
68-
69-
return ipfs.files.mv(source, dest, {
70-
parents,
71-
recursive,
72-
cidVersion,
73-
hashAlg,
74-
flush,
75-
shardSplitThreshold
76-
})
77-
})())
66+
return ipfs.files.mv(source, dest, {
67+
parents,
68+
recursive,
69+
cidVersion,
70+
hashAlg,
71+
flush,
72+
shardSplitThreshold
73+
})
7874
}
7975
}

packages/ipfs-mfs/src/cli/read.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@ module.exports = {
1818
}
1919
},
2020

21-
handler (argv) {
21+
async handler (argv) {
2222
const {
23+
ctx: { ipfs, print },
2324
path,
24-
getIpfs,
25-
print,
2625
offset,
2726
length
2827
} = argv
2928

30-
argv.resolve((async () => {
31-
const ipfs = await getIpfs()
32-
33-
for await (const buffer of ipfs.files.read(path, {
34-
offset,
35-
length
36-
})) {
37-
print(buffer, false)
38-
}
39-
})())
29+
for await (const buffer of ipfs.files.read(path, {
30+
offset,
31+
length
32+
})) {
33+
print(buffer, false)
34+
}
4035
}
4136
}

packages/ipfs-mfs/src/cli/rm.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ module.exports = {
2121

2222
handler (argv) {
2323
const {
24+
ctx: { ipfs },
2425
path,
25-
getIpfs,
2626
recursive
2727
} = argv
2828

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

packages/ipfs-mfs/src/cli/stat.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,36 @@ Mtime: <mtime>`,
5252

5353
handler (argv) {
5454
const {
55+
ctx: { ipfs, print },
5556
path,
56-
getIpfs,
57-
print,
5857
format,
5958
hash,
6059
size,
6160
withLocal,
6261
cidBase
6362
} = argv
6463

65-
argv.resolve((async () => {
66-
const ipfs = await getIpfs()
64+
return ipfs.files.stat(path, {
65+
withLocal
66+
})
67+
.then((stats) => {
68+
if (hash) {
69+
return print(stats.cid.toString(cidBase))
70+
}
6771

68-
return ipfs.files.stat(path, {
69-
withLocal
70-
})
71-
.then((stats) => {
72-
if (hash) {
73-
return print(stats.cid.toString(cidBase))
74-
}
75-
76-
if (size) {
77-
return print(stats.size)
78-
}
72+
if (size) {
73+
return print(stats.size)
74+
}
7975

80-
print(format
81-
.replace('<hash>', stats.cid.toString(cidBase))
82-
.replace('<size>', stats.size)
83-
.replace('<cumulsize>', stats.cumulativeSize)
84-
.replace('<childs>', stats.blocks)
85-
.replace('<type>', stats.type)
86-
.replace('<mode>', formatMode(stats.mode, stats.type === 'directory'))
87-
.replace('<mtime>', formatMtime(stats.mtime))
88-
)
89-
})
90-
})())
76+
print(format
77+
.replace('<hash>', stats.cid.toString(cidBase))
78+
.replace('<size>', stats.size)
79+
.replace('<cumulsize>', stats.cumulativeSize)
80+
.replace('<childs>', stats.blocks)
81+
.replace('<type>', stats.type)
82+
.replace('<mode>', formatMode(stats.mode, stats.type === 'directory'))
83+
.replace('<mtime>', formatMtime(stats.mtime))
84+
)
85+
})
9186
}
9287
}

0 commit comments

Comments
 (0)