This repository was archived by the owner on Nov 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdelete.js
62 lines (53 loc) · 1.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const {flags} = require('@oclif/command');
const BaseCommand = require('../../base');
class RecordsDeleteCommand extends BaseCommand {
async run() {
const {flags} = this.parse(RecordsDeleteCommand);
const {isTTY} = process.stdout;
let {name, id} = flags;
const {api, spinner} = this;
if (!name && isTTY) {
const {askDomainName} = require('../../prompts');
const {domainName} = await askDomainName();
name = domainName;
}
if (!id && isTTY) {
// Load all available records of the domain and prompt
try {
spinner.start(`Loading ${name} records...`);
const {body} = await api.domainRecordsGetAll(name);
spinner.stop();
const records = [];
body.domain_records.map(record =>
records.push({
message: `${record.type} ${record.name} ${record.data}`,
value: record.id
})
);
const {askRecordID} = require('../../prompts/records');
const {recordID} = await askRecordID(records);
id = recordID;
} catch (error) {
spinner.stop();
this.error(error.message);
}
}
try {
spinner.start(`Deleting records...`);
const {response} = await api.domainRecordsDelete(name, id);
spinner.stop();
if (response.statusCode === 204) {
this.log(`Domain record deleted!`);
}
} catch (error) {
spinner.stop();
this.error(error.message);
}
}
}
RecordsDeleteCommand.description = `delete a domain record`;
RecordsDeleteCommand.flags = {
name: flags.string({char: 'n', description: 'domain name'}),
id: flags.string({char: 'i', description: 'domain record ID'})
};
module.exports = RecordsDeleteCommand;