forked from ipfs/aegir
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·64 lines (55 loc) · 1.92 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
#! /usr/bin/env node
'use strict'
process.on('unhandledRejection', (err) => {
throw err
})
const updateNotifier = require('update-notifier')
const chalk = require('chalk')
const pkg = require('./package.json')
updateNotifier({
pkg: pkg,
isGlobal: false
}).notify()
const cli = require('yargs')
cli.env('TASEGIR')
.usage('Usage: $0 <command> [options]')
.example('$0 build', 'Runs the build command to bundle JS code for the browser.')
.example('npx $0 build', 'Can be used with `npx` to use a local version')
.example('$0 test -t webworker -- --browsers Firefox', 'If the command supports `--` can be used to forward options to the underlying tool.')
.example('npm test -- -- --browsers Firefox', 'If `npm test` translates to `tasegir test -t browser` and you want to forward options you need to use `-- --` instead.')
.epilog('Use `$0 <command> --help` to learn more about each command.')
.commandDir('cmds')
.demandCommand(1, 'You need at least one command.')
.option('D', {
desc: 'Show debug output.',
type: 'boolean',
default: false,
alias: 'debug'
})
.help()
.alias('h', 'help')
.alias('v', 'version')
.group(['help', 'version', 'debug'], 'Global Options:')
.wrap(cli.terminalWidth())
.parserConfiguration({ 'populate--': true })
.strict()
const args = cli.fail((msg, err, yargs) => {
if (msg) {
yargs.showHelp()
console.error(chalk.red(msg)) // eslint-disable-line no-console
}
if (err) {
console.error(chalk.red(err.message)) // eslint-disable-line no-console
if (args.debug) {
// errors from execa output the child_process stderr
if (err && err.stderr) {
console.error('Error running command: ', err.cmd, '\n') // eslint-disable-line no-console
console.error(err.stderr) // eslint-disable-line no-console
} else {
console.error(chalk.gray(err.stack)) // eslint-disable-line no-console
}
}
}
process.exit(1)
})
.argv