-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit
More file actions
executable file
·52 lines (43 loc) · 1.54 KB
/
git
File metadata and controls
executable file
·52 lines (43 loc) · 1.54 KB
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
const {parserSync} = require('shargs')
const {command, flag, string, subcommand, variadicPos} = require('shargs/opts')
const {flagAsNumber, flagsAsBools, splitShortOpts} = require('shargs/parser')
const {desc, optsListsWith, space, synopses, usage} = require('shargs/usage')
const init = subcommand([
flag('quiet', ['-q', '--quiet'], {desc: 'Only print error and warning messages.'})
])
const commit = subcommand([
flag('all', ['-a', '--all'], {desc: 'Automatically stage files that have been modified and deleted.'}),
string('message', ['-m', '--message'], {descArg: 'msg', desc: 'Use <msg> as the commit message.'}),
variadicPos('file', {desc: 'A list of files to commit.'})
])
const opts = [
flag('help', ['--help'], {desc: 'Print this help message.'}),
init('init', ['init'], {desc: 'Create an empty Git repository or reinitialize an existing one.'}),
commit('commit', ['commit'], {desc: 'Record changes to the repository.'})
]
const git = command('git', opts, {desc: 'A simple command-line interface for git.'})
const stages = {
argv: [splitShortOpts],
args: [flagAsNumber('quiet'), flagsAsBools]
}
const parser = parserSync(stages)
const parse = parser(git)
const argv = process.argv.slice(2)
const res = parse(argv)
if (res.args.help) {
const style = {
line: [{width: 50}],
cols: [{width: 20}, {width: 30}]
}
const help = usage([
synopses,
space,
optsListsWith({pad: 2}),
space,
desc
])(git)(style)
console.log(help)
} else {
console.log(JSON.stringify(res, null, 2))
}