forked from isomorphic-git/isomorphic-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.cjs
executable file
·41 lines (36 loc) · 987 Bytes
/
cli.cjs
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
#!/usr/bin/env node
const fs = require('fs')
const minimisted = require('minimisted')
const git = require('.')
const http = require('./http/node')
// This really isn't much of a CLI. It's mostly for testing.
// But it's very versatile and works surprisingly well.
minimisted(async function({ _: [command, ...args], ...opts }) {
try {
const result = await git[command](
Object.assign(
{
fs,
http,
dir: '.',
onAuth: () => ({ username: opts.username, password: opts.password }),
headers: {
'User-Agent': `git/isogit-${git.version()}`,
},
},
opts
)
)
if (result === undefined) return
// detect streams
if (typeof result.on === 'function') {
result.pipe(process.stdout)
} else {
console.log(JSON.stringify(result, null, 2))
}
} catch (err) {
process.stderr.write(err.message + '\n')
console.log(err)
process.exit(1)
}
})