-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·66 lines (59 loc) · 1.79 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
#!/usr/bin/env node
'use strict';
const program = require('commander');
const fs = require('fs');
const path = require('path');
const Label = require('./lib/label');
const debug = require('debug')('gh-label-tmpl:index');
program
.version('0.0.1')
.option('-o, --owner [owner]', 'repo owner')
.option('-r, --repo [repo]', 'repo name')
.option('-t, --token [token]', 'github token')
.option('-e, --export [filename]', 'export the lables to json file [filename]')
.option('-d, --del', 'delete all existed labels')
.option('-i, --import [filename]', 'import the labels from json file [filename]')
//.option('-c, --config [config file]', 'use config file', 'config.json') //TODO or get git info?
.parse(process.argv);
if (!program.owner) {
program.help((txt) => {
console.error('should specify repo onwer!');
return txt;
});
}
if (!program.repo) {
program.help((txt) => {
console.error('should specify repo name!');
return txt;
});
}
const main = () => {
const lbl = new Label(program.owner, program.repo, program.token);
if (program.export) {
const exportedFile = path.resolve(program.export);
return lbl.getAll()
.then(labels => {
fs.writeFileSync(exportedFile, JSON.stringify(labels, null, 2));
console.log(`All labels exported to ${exportedFile}`);
});
}
if (program.del) {
return lbl.removeAll()
.then(() => {
console.log('All labels removed.');
});
}
if (program.import) {
debug('abs file path: %s', path.resolve(program.import));
const labels = require(path.resolve(program.import));
return lbl.createAll(labels)
.then(() => {
console.log('All labels created.');
});
}
program.help((txt) => {
console.error('No action specified!');
return txt;
});
};
main();