-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.js
54 lines (37 loc) · 1.3 KB
/
remove.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
const {Command, flags} = require('@oclif/command'),
ora = require('ora'),
{read, removeProfile} = require("../../lib/json_utility"),
{promptUser, ConfirmPrompt} = require("../../lib/prompt");
class RemoveProfile extends Command {
async run() {
let spinner = await ora(),
{flags} = this.parse(RemoveProfile),
name = flags.name || false;
try{
if(!name){
name = await promptUser(`Please type in your profile name to remove : `, true, `"Profile Name" cannot be empty`);
}
const profiles = await read();
if(profiles.length){
const found = await profiles.find(p => p.profileName.trim() == name.trim());
if(!found){
spinner.fail(`Profile "${name}" not found!`);
return;
}
if(await ConfirmPrompt(`Are you sure, wants to delete "${name}" profile?`)){
await removeProfile(name);
spinner.succeed(`Profile "${name}" removed!`)
}
}
else
spinner.fail(`Profile "${name}" not found!`);
}catch(err){
spinner.fail(`Error : ${err.message}`);
}
}
}
RemoveProfile.description = `Remove YouTube profile`;
RemoveProfile.flags = {
name: flags.string({char: 'n', description: 'name of the profile to remove'}),
}
module.exports = RemoveProfile