forked from fauna/fauna-shell
/
delete-key.js
45 lines (39 loc) · 1003 Bytes
/
delete-key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const FaunaCommand = require('../lib/fauna-command.js')
const { errorOut } = require('../lib/misc.js')
const faunadb = require('faunadb')
const q = faunadb.query
class DeleteKeyCommand extends FaunaCommand {
async run() {
const keyname = this.args.keyname
const log = this.log
return this.query(
q.Delete(q.Ref(q.Keys(null), keyname)),
`deleting key ${keyname}`,
function (success) {
log(`key ${success.ref.id} deleted`)
},
function (error) {
if (error.message === 'instance not found') {
errorOut(`Key ${keyname} not found`, 1)
} else {
errorOut(error.message, 1)
}
}
)
}
}
DeleteKeyCommand.description = `
Deletes a key
`
DeleteKeyCommand.examples = ['$ fauna delete-key 123456789012345678']
DeleteKeyCommand.flags = {
...FaunaCommand.flags,
}
DeleteKeyCommand.args = [
{
name: 'keyname',
required: true,
description: 'key name',
},
]
module.exports = DeleteKeyCommand