Skip to content

Commit

Permalink
feat(startDeamon): allow passing flags to ipfs daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenet committed Sep 16, 2016
1 parent 0deb7e5 commit c7ea808
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,24 @@ module.exports = class Node {
}
}

startDaemon (done) {
startDaemon (flags, done) {
if (typeof(flags) === 'function' && typeof(done) === 'undefined') {
done = flags
flags = []
}

const node = this
parseConfig(node.path, (err, conf) => {
if (err) return done(err)

let stdout = ""
let args = ['daemon'].concat(flags || [])

// strategy:
// - run subprocess
// - listen for API addr on stdout (success)
// - or an early exit or error (failure)
node.subprocess = run(node.exec, ['daemon'], {env: node.env})
node.subprocess = run(node.exec, args, {env: node.env})
node.subprocess.on('error', onErr)
.on('data', onData)

Expand Down
22 changes: 22 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,25 @@ describe('ipfs-api version', function () {
})
})
})

describe('node startDaemon', () => {
it('allows passing flags', (done) => {
ipfsd.disposable((err, node) => {
if (err) throw err
node.startDaemon(["--should-not-exist"], (err, ignore) => {
if (!err) {
throw new Error("should have errored")
}

let errStr = "Unrecognized option 'should-not-exist'"

err = ""+ err
if (err.indexOf(errStr) >= 0) {
done() // correct error
}

throw err
})
})
})
})

0 comments on commit c7ea808

Please sign in to comment.