-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
77 lines (68 loc) · 1.44 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
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
'use strict'
const Updater = require('.')
const minimist = require('minimist')
const argv = minimist(process.argv.slice(2), {
boolean: [
'dryRun',
'glob',
'force',
'commit',
'verbose',
'version',
'help'
],
alias: {
d: 'dryRun',
'dry-run': 'dryRun',
g: 'glob',
f: 'force',
v: 'version',
h: 'help'
},
default: {
dryRun: false,
glob: true,
commit: true,
force: false,
verbose: false,
version: false,
help: false
}
})
const target = argv._[0]
const files = argv._.slice(1)
if (argv.version) {
console.log('dotnet-bump v%s', require('./package.json').version)
process.exit(0)
}
if (!target || argv.help) {
const path = require('path')
const usageFile = path.join(__dirname, 'usage.txt')
const usage = require('fs').readFileSync(usageFile, 'utf8').trim()
if (argv.help) {
console.log(usage)
process.exit(0)
} else {
console.error(usage)
console.error('\nA target is required.')
process.exit(1)
}
}
if (!files.length) {
files.push('.')
}
new Updater(argv).on('warning', warn).update(target, files, (err, files) => {
if (err && argv.verbose) {
throw err
} else if (err) {
console.error(err.message || err)
process.exit(1)
} else if (files.length === 0) {
console.error('0 matching files.')
process.exit(1)
}
})
function warn (message, ...args) {
console.error('Warning. ' + message, ...args)
}