Skip to content

Commit

Permalink
move discovery key to option (#869)
Browse files Browse the repository at this point in the history
* move discovery key to option

* add discovery key test
  • Loading branch information
joehand authored Sep 28, 2017
1 parent 0491254 commit d66d40c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/commands/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ module.exports = {
' dat keys import import dat secret key to make a dat writable',
''
].join('\n'),
options: []
options: [
{
name: 'discovery',
boolean: true,
default: false,
help: 'Print Discovery Key'
}
]
}

function keys (opts) {
Expand Down Expand Up @@ -40,7 +47,8 @@ function run (dat, opts) {
root: {
command: function () {
console.log(`dat://${dat.key.toString('hex')}`)
console.log(`Discovery key: ${dat.archive.discoveryKey.toString('hex')}`)
if (opts.discovery) console.log(`Discovery key: ${dat.archive.discoveryKey.toString('hex')}`)
process.exit()
}
},
commands: [
Expand Down
18 changes: 18 additions & 0 deletions test/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ test('keys - print keys', function (t) {
var cmd = dat + ' keys '
var st = spawn(t, cmd, {cwd: fixtures})

st.stdout.match(function (output) {
if (output.indexOf('dat://') === -1) return false
t.ok(output.indexOf(shareDat.key.toString('hex') > -1), 'prints key')
st.kill()
return true
})
st.stderr.empty()
st.end()
})
})
})

test('keys - print discovery key', function (t) {
help.shareFixtures(function (_, shareDat) {
shareDat.close(function () {
var cmd = dat + ' keys --discovery'
var st = spawn(t, cmd, {cwd: fixtures})

st.stdout.match(function (output) {
if (output.indexOf('Discovery') === -1) return false
t.ok(output.indexOf(shareDat.key.toString('hex') > -1), 'prints key')
Expand Down

0 comments on commit d66d40c

Please sign in to comment.