-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·49 lines (44 loc) · 1.11 KB
/
cli.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
#!/usr/bin/env node
'use strict'
const favjunk = require('./favjunk');
const yargs = require('yargs');
const showList = function (symbol, list) {
list.forEach((item) => {
console.log(`${symbol} [${item.hash}] ${item.path}`);
});
};
const options = {
path: {
alias: 'p',
type: 'string',
desc: 'path',
default: '.',
},
recursive: {
alias: 'r',
type: 'boolean',
desc: 'recursively',
default: false,
},
};
yargs
.detectLocale(false)
.command('$0', 'unlink matched file(s)', options, (argv) => {
const list = favjunk.exec(argv.path, argv.recursive);
showList('D', list);
})
.command('check', 'show matched file(s)', options, (argv) => {
const list = favjunk.check(argv.path, argv.recursive);
showList('M', list);
})
.command('add <file...>', 'add file(s) to favorite list', {}, (argv) => {
const list = favjunk.add(argv.file);
showList('+', list);
})
.command('rm <file...>', 'remove file(s) from favorite list', {}, (argv) => {
const list = favjunk.remove(argv.file);
showList('-', list);
})
.help()
.alias('help', 'h')
.argv;