-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.js
61 lines (56 loc) · 1.79 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
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const ghDescription = require('./')
const gitconfig = require('gitconfiglocal')
const pify = require('pify')
const ghauth = pify(require('ghauth'))
const authOptions = {
configName: 'gh-description',
note: 'Set and get a GitHub repository description',
userAgent: 'github.com/RichardLitt/gh-description',
scopes: ['repo']
}
var cli = meow([`
Usage
$ gh-description [input]
Options
-e, --enterprise Specify a different GitHub endpoint
Examples
$ gh-description
Set and get a GitHub repository description
$ gh-description RichardLitt/gh-description
Set and get a GitHub repository description
$ gh-description RichardLitt/gh-description 'ponies and unicorns'
New description: ponies and unicorns
$ gh-description RichardLitt/gh-description -e
New enterprise description: Engage
$ gh-description RichardLitt/gh-description -e https://scottymcscottface.co.uk
New enterprise description: Beam Me Up
`], {
alias: {
e: 'enterprise'
}
})
pify(gitconfig)(process.cwd())
.then(config => {
if (config && config.remote && config.remote.origin && config.remote.origin.url) {
var url = config.remote.origin.url
return url.match(/([^/:]+\/[^/.]+)(\.git)?$/)[1]
}
}).then((res) => {
if (res && cli.input.length === 0) {
cli.input[0] = res
}
return (cli.input[1]) ? ghauth(authOptions) : { token: null }
}).then((authData) => {
return ghDescription(cli.input[0], cli.input[1], cli.flags, authData.token)
}).then(function (response) {
if (!response.method) {
console.log(response)
} else if (response.method === 'patch') {
console.log(`New description:\n${response.description}`)
} else if (response.method === 'get') {
console.log(`${response.description}`)
}
})