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

refactor: use getIpfs not ipfs from argv #37

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/cli/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ module.exports = {
let {
source,
dest,
ipfs,
getIpfs,
parents,
format,
hashAlg,
shardSplitThreshold
} = argv

argv.resolve(
ipfs.files.cp(source, dest, {
argv.resolve((async () => {
const ipfs = await getIpfs()
return ipfs.files.cp(source, dest, {
parents,
format,
hashAlg,
shardSplitThreshold
})
)
})())
}
}
9 changes: 5 additions & 4 deletions src/cli/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ module.exports = {
handler (argv) {
let {
path,
ipfs
getIpfs
} = argv

argv.resolve(
ipfs.files.flush(path || FILE_SEPARATOR, {})
)
argv.resolve((async () => {
const ipfs = await getIpfs()
return ipfs.files.flush(path || FILE_SEPARATOR, {})
})())
}
}
9 changes: 5 additions & 4 deletions src/cli/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ module.exports = {
handler (argv) {
let {
path,
ipfs,
getIpfs,
long,
sort,
cidBase
} = argv

argv.resolve(
new Promise((resolve, reject) => {
argv.resolve((async () => {
const ipfs = await getIpfs()
return new Promise((resolve, reject) => {
if (sort) {
ipfs.files.ls(path || FILE_SEPARATOR, {
long,
Expand Down Expand Up @@ -98,6 +99,6 @@ module.exports = {
})
)
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,24 @@ module.exports = {
handler (argv) {
let {
path,
ipfs,
getIpfs,
parents,
cidVersion,
hashAlg,
flush,
shardSplitThreshold
} = argv

argv.resolve(
ipfs.files.mkdir(path, {
argv.resolve((async () => {
const ipfs = await getIpfs()

return ipfs.files.mkdir(path, {
parents,
cidVersion,
hashAlg,
flush,
shardSplitThreshold
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ module.exports = {
let {
source,
dest,
ipfs,
getIpfs,
parents,
recursive,
shardSplitThreshold
} = argv

argv.resolve(
ipfs.files.mv(source, dest, {
argv.resolve((async () => {
const ipfs = await getIpfs()

return ipfs.files.mv(source, dest, {
parents,
recursive,
shardSplitThreshold
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ module.exports = {
handler (argv) {
let {
path,
ipfs,
getIpfs,
offset,
length
} = argv

argv.resolve(
new Promise((resolve, reject) => {
argv.resolve((async () => {
const ipfs = await getIpfs()

return new Promise((resolve, reject) => {
pull(
ipfs.files.readPullStream(path, {
offset,
Expand All @@ -52,6 +54,6 @@ module.exports = {
})
)
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ module.exports = {
handler (argv) {
let {
path,
ipfs,
getIpfs,
recursive
} = argv

argv.resolve(
ipfs.files.rm(path, {
argv.resolve((async () => {
const ipfs = await getIpfs()

return ipfs.files.rm(path, {
recursive
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ Type: <type>`,
handler (argv) {
let {
path,
ipfs,
getIpfs,
format,
hash,
size,
withLocal
} = argv

argv.resolve(
ipfs.files.stat(path, {
argv.resolve((async () => {
const ipfs = await getIpfs()

return ipfs.files.stat(path, {
withLocal
})
.then((stats) => {
Expand All @@ -79,6 +81,6 @@ Type: <type>`,
.replace('<type>', stats.type)
)
})
)
})())
}
}
10 changes: 6 additions & 4 deletions src/cli/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = {
handler (argv) {
let {
path,
ipfs,
getIpfs,
offset,
length,
create,
Expand All @@ -106,8 +106,10 @@ module.exports = {
shardSplitThreshold
} = argv

argv.resolve(
ipfs.files.write(path, process.stdin, {
argv.resolve((async () => {
const ipfs = await getIpfs()

return ipfs.files.write(path, process.stdin, {
offset,
length,
create,
Expand All @@ -123,6 +125,6 @@ module.exports = {
flush,
shardSplitThreshold
})
)
})())
}
}