-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·51 lines (38 loc) · 1.5 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
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const { version, description } = require('./package.json');
const { main, clean } = require('./commands');
const getWorkingDirectory = () => {
const { directory } = program;
return directory ? path.resolve(process.cwd(), directory) : process.cwd();
};
program
.usage('[opts]')
.description(description)
.version(version, '-v, --version', 'print the program\'s version number')
.option('-d, --directory [path]', 'specify a directory to scan (default: the current directory)')
.option('-r, --recursive', 'whether to keep running recursively or not. include subdirectories or not (default: false)');
program
.command('scan')
.description('Scans a directory\'s subdirectories for non-standard branches (default command)')
.action(() => {
const workingDirectory = getWorkingDirectory();
const { recursive } = program;
main(workingDirectory, recursive);
});
program
.command('clean')
.description('Clean those pesky leftover branches')
.action(() => {
const workingDirectory = getWorkingDirectory();
const { recursive } = program;
clean(workingDirectory, recursive);
});
program.parse(process.argv);
const commandUsed = program.args.some((arg) => arg instanceof program.Command);
if (!commandUsed) {
const workingDirectory = getWorkingDirectory();
const { recursive } = program;
main(workingDirectory, recursive);
}