Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
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
30 changes: 19 additions & 11 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,27 @@ if (args[0] === 'daemon' || args[0] === 'init') {
.completion()
.parse(args)
} else {
utils.getIPFS((err, ipfs, cleanup) => {
if (err) { throw err }
// here we have to make a separate yargs instance with
// only the `api` option because we need this before doing
// the final yargs parse where the command handler is invoked..
yargs().option('api').parse(process.argv, (err, argv, output) => {
if (err) {
throw err
}
utils.getIPFS(argv.api, (err, ipfs, cleanup) => {
if (err) { throw err }

cli
.help()
.strict(false)
.completion()
.parse(args, { ipfs: ipfs }, (err, argv, output) => {
if (output) { print(output) }
cli
.help()
.strict(false)
.completion()
.parse(args, { ipfs: ipfs }, (err, argv, output) => {
if (output) { print(output) }

cleanup(() => {
if (err) { throw err }
cleanup(() => {
if (err) { throw err }
})
})
})
})
})
}
18 changes: 10 additions & 8 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ function isDaemonOn () {
}

exports.getAPICtl = getAPICtl
function getAPICtl () {
if (!isDaemonOn()) {
function getAPICtl (apiAddr) {
if (!apiAddr && !isDaemonOn()) {
throw new Error('daemon is not on')
}
const apiPath = path.join(exports.getRepoPath(), 'api')
const apiAddr = multiaddr(fs.readFileSync(apiPath).toString())
return APIctl(apiAddr.toString())
if (!apiAddr) {
const apiPath = path.join(exports.getRepoPath(), 'api')
apiAddr = multiaddr(fs.readFileSync(apiPath).toString()).toString()
}
return APIctl(apiAddr)
}

exports.getIPFS = (callback) => {
if (isDaemonOn()) {
return callback(null, getAPICtl(), (cb) => cb())
exports.getIPFS = (apiAddr, callback) => {
if (apiAddr || isDaemonOn()) {
return callback(null, getAPICtl(apiAddr), (cb) => cb())
}

const node = new IPFS({
Expand Down