This repository has been archived by the owner on Feb 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (82 loc) · 2.43 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
const cli = require('commander');
const inquirer = require('inquirer');
const pkg = require('./package.json');
const define = require('./define');
const {create, remove, list, isExist, getfilename, getcallname} = require('./src/shellcut');
cli.version(pkg.version);
cli.command('create <call> <cmd...>') // <name> : require, [name] : option
.description('create cmd')
.option('-f, --force', 'ignore already saved same call name.', false)
.action(function(call, cmd) {
if(this.force !== true && isExist(call)) {
inquirer.prompt([
{
type: 'confirm',
name: 'proceed',
message: `'${call}' is already exist. will be replaced. do you want proceed?`,
default: false
}
]).then(function(answer) {
if(answer.proceed) {
create(call, cmd);
}
});
}
else {
create(call, cmd);
}
});
cli.command('list')
.description('show existed shellcut commands.')
.option('-c, --call <arg>', 'filter by call name.')
.option('-o, --cmd <arg>', 'filter by original cmd.')
.action(function() {
const result = list(this.call, this.cmd);
console.log(result);
});
cli.command('remove <call>')
.description('remove shellcut command.')
.option('-f, --force', "ignore confirm", false)
.action(function(call) {
if(this.force !== true) {
inquirer.prompt([
{
type: 'confirm',
name: 'proceed',
message: `This task cannot be undone. do you want proceed?`,
default: false
}
]).then(function(answer) {
if(answer.proceed) {
remove(call);
}
});
}
else {
remove(call);
}
});
cli.command('clear')
.description('remove all shellcut commands.')
.option('-f', '--force', 'ignore confirm', false)
.action(function() {
if(this.force !== false){
inquirer.prompt([
{
type: 'confirm',
name: 'proceed',
message: `This task cannot be undone. do you want proceed?`,
default: false
}
]).then(function(answer) {
if(answer.proceed) {
list().forEach(elem => {
const call = getcallname(elem);
remove(call);
});
}
});
}
});
cli.parse(process.argv);