Skip to content

Commit c7ea808

Browse files
committed
feat(startDeamon): allow passing flags to ipfs daemon
1 parent 0deb7e5 commit c7ea808

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Diff for: src/node.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,24 @@ module.exports = class Node {
117117
}
118118
}
119119

120-
startDaemon (done) {
120+
startDaemon (flags, done) {
121+
if (typeof(flags) === 'function' && typeof(done) === 'undefined') {
122+
done = flags
123+
flags = []
124+
}
125+
121126
const node = this
122127
parseConfig(node.path, (err, conf) => {
123128
if (err) return done(err)
124129

125130
let stdout = ""
131+
let args = ['daemon'].concat(flags || [])
126132

127133
// strategy:
128134
// - run subprocess
129135
// - listen for API addr on stdout (success)
130136
// - or an early exit or error (failure)
131-
node.subprocess = run(node.exec, ['daemon'], {env: node.env})
137+
node.subprocess = run(node.exec, args, {env: node.env})
132138
node.subprocess.on('error', onErr)
133139
.on('data', onData)
134140

Diff for: test/index.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,25 @@ describe('ipfs-api version', function () {
369369
})
370370
})
371371
})
372+
373+
describe('node startDaemon', () => {
374+
it('allows passing flags', (done) => {
375+
ipfsd.disposable((err, node) => {
376+
if (err) throw err
377+
node.startDaemon(["--should-not-exist"], (err, ignore) => {
378+
if (!err) {
379+
throw new Error("should have errored")
380+
}
381+
382+
let errStr = "Unrecognized option 'should-not-exist'"
383+
384+
err = ""+ err
385+
if (err.indexOf(errStr) >= 0) {
386+
done() // correct error
387+
}
388+
389+
throw err
390+
})
391+
})
392+
})
393+
})

0 commit comments

Comments
 (0)