|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -const parse = require('parse-github-repo-url') |
4 | | -const emptyGitHubCommit = require('..') |
5 | | - |
6 | 3 | const token = process.env.TOKEN || process.env.GITHUB_TOKEN |
7 | 4 | if (!token) { |
8 | 5 | console.error('Cannot find TOKEN or GITHUB_TOKEN') |
9 | 6 | process.exit(1) |
10 | 7 | } |
11 | | -const repoWhat = process.argv[2] |
12 | | -const message = process.argv[3] |
13 | | -if (!repoWhat || !message) { |
14 | | - repoWhat.log('usage: empty-commit <repo url> <commit message>') |
| 8 | + |
| 9 | +const parse = require('parse-github-repo-url') |
| 10 | +const options = require('minimist')(process.argv, { |
| 11 | + alias: { |
| 12 | + repo: 'r', |
| 13 | + message: 'm', |
| 14 | + branch: 'b' |
| 15 | + }, |
| 16 | + default: { |
| 17 | + branch: 'master' |
| 18 | + } |
| 19 | +}) |
| 20 | +const emptyGitHubCommit = require('..') |
| 21 | + |
| 22 | +if (!options.repo || !options.message) { |
| 23 | + console.log('usage: empty-commit --repo <github repo> --message <commit message>') |
| 24 | + console.log('optional args') |
| 25 | + console.log(' --branch <master>') |
15 | 26 | process.exit(1) |
16 | 27 | } |
17 | | -console.log('Making empty commit in', repoWhat) |
18 | | -console.log('message:', message) |
| 28 | +console.log('Making empty commit in', options.repo) |
| 29 | +console.log('message:', options.message) |
| 30 | +console.log('branch:', options.branch) |
19 | 31 |
|
20 | | -const parsed = parse(repoWhat) |
| 32 | +const parsed = parse(options.repo) |
21 | 33 | const user = parsed[0] |
22 | 34 | const repo = parsed[1] |
23 | 35 | if (!user || !repo) { |
24 | | - console.error('Could not parse repo', repoWhat) |
| 36 | + console.error('Could not parse GitHub repo', options.repo) |
25 | 37 | process.exit(1) |
26 | 38 | } |
27 | 39 |
|
28 | 40 | emptyGitHubCommit({ |
29 | 41 | owner: user, |
30 | 42 | repo: repo, |
31 | | - token: process.env.TOKEN, |
32 | | - fullyQualifiedRef: 'heads/master' |
| 43 | + token: token, |
| 44 | + fullyQualifiedRef: `heads/${options.branch}` |
33 | 45 | }).then(console.log, e => { |
34 | 46 | console.error(e) |
35 | 47 | process.exit(1) |
|
0 commit comments