-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.js
47 lines (41 loc) · 1.31 KB
/
delete.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
46
47
const argv = require('minimist')(process.argv.slice(2))
const chalk = require('chalk')
const confirm = require('prompt-confirm')
const config = require('../lib/config')()
module.exports = async () => {
const client = argv['_'][1] || null
const instance = argv['_'][2] || null
const currentConfig = config.get()
let newConfig = {}
if (currentConfig) {
let found = false
newConfig = Object.assign({}, newConfig, currentConfig)
if (client && instance) {
if (
Object.prototype.isPrototypeOf.call(newConfig, client) &&
Object.prototype.isPrototypeOf.call(newConfig[client], instance)
) {
found = true
delete newConfig[client][instance]
} else {
console.log(chalk.red.bold(`\n✖ Config does not contain client '${client}' with instance '${instance}'.\n`))
}
} else if (client) {
if (Object.prototype.isPrototypeOf.call(newConfig, client)) {
found = true
delete newConfig[client]
} else {
console.log(chalk.red.bold(`\n✖ Config does not contain client '${client}'.\n`))
}
}
if (found) {
console.log('')
const prompt = new confirm('Confirm Delete?')
prompt.ask(function (confirmed) {
if (confirmed) {
config.set(newConfig, true)
}
})
}
}
}