-
Notifications
You must be signed in to change notification settings - Fork 5
/
keepUser.js
executable file
·52 lines (39 loc) · 1.22 KB
/
keepUser.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
#!/usr/bin/env node
'use strict';
(() => {
const meow = require('meow');
const path = require('path');
const data = require('./impl/data');
const DbFile = require('./impl/dbFile');
const cli = meow(`
Mark a user as not to be deleted.
usage:
$ ./keepUser.js USER REASON
$ ./keepUser.js --help
$ ./keepUser.js --version
positional arguments:
USER GitHub username, e.g. AurelienLourot
REASON Usually a link to an issue
`);
if (cli.input.length < 2) {
console.error('Error: USER and/or REASON arguments missing. See `./keepUser.js --help`.');
process.exit(1);
}
if (cli.input.length > 2) {
console.error('Error: too many positional arguments. See `./keepUser.js --help`.');
process.exit(1);
}
const user = cli.input[0];
const reason = cli.input[1];
const userId = user.toLowerCase();
const userFile = new DbFile(path.join(data.users, `${userId}.json`));
if (!userFile.login) {
throw `${user} doesn't exist`;
}
if (userFile.ghuser_deleted_because) {
throw `${user} has already been deleted because ${userFile.ghuser_deleted_because}`;
}
userFile.ghuser_keep_because = reason;
userFile.write();
console.log(`${user} marked as not to be deleted.`);
})();