This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.js
executable file
·67 lines (56 loc) · 1.78 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
'use strict';
(async () => {
const meow = require('meow');
const ora = require('ora');
const githubContribs = require('.');
const cli = meow(`
usage:
$ github-contribs [--quiet|--verbose] [--since YYYY-MM-DD] [--until YYYY-MM-DD] [--issues] USER
$ github-contribs --help
$ github-contribs --version
positional arguments:
USER GitHub username, e.g. AurelienLourot
optional arguments:
--quiet do not show progress while querying GitHub, only the final result
--verbose show debugging information
--since YYYY-MM-DD limit the results (default: first day at GitHub)
--until YYYY-MM-DD limit the results (default: today)
--issues fetches not only commits and PRs but also issues
--version show program's version number and exit
--help show this help message and exit
`, {
boolean: [
'quiet',
'verbose',
'issues',
],
string: [
'since',
'until',
],
});
if (cli.flags.quiet && cli.flags.verbose) {
console.error('Error: --quiet and --verbose are mutually exclusive. See `github-contribs --help`.');
process.exit(1);
}
if (cli.input.length < 1) {
console.error('Error: USER argument missing. See `github-contribs --help`.');
process.exit(1);
}
if (cli.input.length > 1) {
console.error('Error: too many positional arguments. See `github-contribs --help`.');
process.exit(1);
}
const user = cli.input[0];
const repos = await githubContribs.fetch(
user, cli.flags.since, cli.flags.until, !cli.flags.quiet && ora, cli.flags.verbose && console,
cli.flags.issues
);
if (!cli.flags.quiet) {
console.log(`${repos.size} repo(s) found:`);
}
for (const repo of repos) {
console.log(repo);
}
})();