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

Commit fd22958

Browse files
committed
chore: convert all commands return resolvable promises
License: MIT Signed-off-by: achingbrain <[email protected]>
1 parent 25a5465 commit fd22958

File tree

9 files changed

+122
-104
lines changed

9 files changed

+122
-104
lines changed

src/cli/cp.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ module.exports = {
4141
hash
4242
} = argv
4343

44-
return ipfs.files.cp(source, dest, {
45-
parents,
46-
format,
47-
hashAlg: hash
48-
})
44+
argv.resolve(
45+
ipfs.files.cp(source, dest, {
46+
parents,
47+
format,
48+
hashAlg: hash
49+
})
50+
)
4951
}
5052
}

src/cli/flush.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module.exports = {
1717
ipfs
1818
} = argv
1919

20-
return ipfs.files.flush(path || FILE_SEPARATOR, {})
20+
argv.resolve(
21+
ipfs.files.flush(path || FILE_SEPARATOR, {})
22+
)
2123
}
2224
}

src/cli/ls.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,47 @@ module.exports = {
3030
long
3131
} = argv
3232

33-
return ipfs.files.ls(path || FILE_SEPARATOR)
34-
.then(files => {
35-
if (long) {
36-
const table = []
37-
const lengths = {}
38-
39-
files.forEach(link => {
40-
const row = {
41-
name: `${link.name}`,
42-
hash: `${link.hash}`,
43-
size: `${link.size}`
44-
}
45-
46-
Object.keys(row).forEach(key => {
47-
const value = row[key]
48-
49-
lengths[key] = lengths[key] > value.length ? lengths[key] : value.length
33+
argv.resolve(
34+
ipfs.files.ls(path || FILE_SEPARATOR)
35+
.then(files => {
36+
if (long) {
37+
const table = []
38+
const lengths = {}
39+
40+
files.forEach(link => {
41+
const row = {
42+
name: `${link.name}`,
43+
hash: `${link.hash}`,
44+
size: `${link.size}`
45+
}
46+
47+
Object.keys(row).forEach(key => {
48+
const value = row[key]
49+
50+
lengths[key] = lengths[key] > value.length ? lengths[key] : value.length
51+
})
52+
53+
table.push(row)
5054
})
5155

52-
table.push(row)
53-
})
56+
table.forEach(row => {
57+
let line = ''
5458

55-
table.forEach(row => {
56-
let line = ''
59+
Object.keys(row).forEach(key => {
60+
const value = row[key]
5761

58-
Object.keys(row).forEach(key => {
59-
const value = row[key]
62+
line += value.padEnd(lengths[key])
63+
line += '\t'
64+
})
6065

61-
line += value.padEnd(lengths[key])
62-
line += '\t'
66+
print(line)
6367
})
6468

65-
print(line)
66-
})
69+
return
70+
}
6771

68-
return
69-
}
70-
71-
files.forEach(link => print(link.name))
72-
})
72+
files.forEach(link => print(link.name))
73+
})
74+
)
7375
}
7476
}

src/cli/mkdir.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ module.exports = {
4444
flush
4545
} = argv
4646

47-
return ipfs.files.mkdir(path, {
48-
parents,
49-
cidVersion,
50-
hash,
51-
flush
52-
})
47+
argv.resolve(
48+
ipfs.files.mkdir(path, {
49+
parents,
50+
cidVersion,
51+
hash,
52+
flush
53+
})
54+
)
5355
}
5456
}

src/cli/mv.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ module.exports = {
3535
recursive
3636
} = argv
3737

38-
return ipfs.files.mv(source, dest, {
39-
parents,
40-
recursive
41-
})
38+
argv.resolve(
39+
ipfs.files.mv(source, dest, {
40+
parents,
41+
recursive
42+
})
43+
)
4244
}
4345
}

src/cli/read.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,30 @@ module.exports = {
3434
length
3535
} = argv
3636

37-
return new Promise((resolve, reject) => {
38-
waterfall([
39-
(cb) => ipfs.files.readPullStream(path, {
40-
offset,
41-
length
42-
}, cb),
43-
(stream, cb) => {
44-
pull(
45-
stream,
46-
through(buffer => {
47-
print(buffer, false)
48-
}),
49-
collect(cb)
50-
)
51-
}
52-
], (error) => {
53-
if (error) {
54-
return reject(error)
55-
}
37+
argv.resolve(
38+
new Promise((resolve, reject) => {
39+
waterfall([
40+
(cb) => ipfs.files.readPullStream(path, {
41+
offset,
42+
length
43+
}, cb),
44+
(stream, cb) => {
45+
pull(
46+
stream,
47+
through(buffer => {
48+
print(buffer, false)
49+
}),
50+
collect(cb)
51+
)
52+
}
53+
], (error) => {
54+
if (error) {
55+
return reject(error)
56+
}
5657

57-
resolve()
58+
resolve()
59+
})
5860
})
59-
})
61+
)
6062
}
6163
}

src/cli/rm.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ module.exports = {
2626
recursive
2727
} = argv
2828

29-
return ipfs.files.rm(path, {
30-
recursive
31-
})
29+
argv.resolve(
30+
ipfs.files.rm(path, {
31+
recursive
32+
})
33+
)
3234
}
3335
}

src/cli/stat.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,27 @@ Type: <type>`,
5454
withLocal
5555
} = argv
5656

57-
return ipfs.files.stat(path, {
58-
withLocal
59-
})
60-
.then((stats) => {
61-
if (hash) {
62-
return print(stats.hash)
63-
}
57+
argv.resolve(
58+
ipfs.files.stat(path, {
59+
withLocal
60+
})
61+
.then((stats) => {
62+
if (hash) {
63+
return print(stats.hash)
64+
}
6465

65-
if (size) {
66-
return print(stats.size)
67-
}
66+
if (size) {
67+
return print(stats.size)
68+
}
6869

69-
print(format
70-
.replace('<hash>', stats.hash)
71-
.replace('<size>', stats.size)
72-
.replace('<cumulsize>', stats.cumulativeSize)
73-
.replace('<childs>', stats.blocks)
74-
.replace('<type>', stats.type)
75-
)
76-
})
70+
print(format
71+
.replace('<hash>', stats.hash)
72+
.replace('<size>', stats.size)
73+
.replace('<cumulsize>', stats.cumulativeSize)
74+
.replace('<childs>', stats.blocks)
75+
.replace('<type>', stats.type)
76+
)
77+
})
78+
)
7779
}
7880
}

src/cli/write.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,21 @@ module.exports = {
8585
flush
8686
} = argv
8787

88-
return ipfs.files.write(path, process.stdin, {
89-
offset,
90-
length,
91-
create,
92-
truncate,
93-
rawLeaves,
94-
cidVersion,
95-
hashAlg,
96-
format,
97-
parents,
98-
progress,
99-
strategy,
100-
flush
101-
})
88+
argv.resolve(
89+
ipfs.files.write(path, process.stdin, {
90+
offset,
91+
length,
92+
create,
93+
truncate,
94+
rawLeaves,
95+
cidVersion,
96+
hashAlg,
97+
format,
98+
parents,
99+
progress,
100+
strategy,
101+
flush
102+
})
103+
)
102104
}
103105
}

0 commit comments

Comments
 (0)