forked from ipfs/aegir
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·68 lines (61 loc) · 1.84 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
#! /usr/bin/env node
/* eslint-disable no-console */
'use strict'
process.on('unhandledRejection', (err) => {
throw err
})
const updateNotifier = require('update-notifier')
const pkg = require('./package.json')
updateNotifier({
pkg: pkg
}).notify()
const cli = require('yargs')
const { userConfig } = require('./src/config/user')
cli
.scriptName('aegir')
.env('AEGIR')
.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 -- --browser firefox', 'If the command supports `--` can be used to forward options to the underlying tool.')
.example('npm test -- -- --browser firefox', 'If `npm test` translates to `aegir 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.')
.middleware((yargs) => {
yargs.fileConfig = userConfig
})
.commandDir('src/cmds')
.help()
.alias('help', 'h')
.alias('version', 'v')
.option('debug', {
desc: 'Show debug output.',
type: 'boolean',
alias: 'd',
default: userConfig.debug
})
.options('ts-repo', {
type: 'boolean',
describe: 'Enable support for Typescript repos.',
default: userConfig.tsRepo
})
.group(['help', 'version', 'debug', 'ts-repo'], 'Global Options:')
.demandCommand(1, 'You need at least one command.')
.wrap(cli.terminalWidth())
.parserConfiguration({ 'populate--': true })
.recommendCommands()
.completion()
.strictCommands()
.fail(false)
async function main () {
try {
await cli.parse()
} catch (err) {
if (cli.parsed && cli.parsed.argv.debug) {
console.error('\n', err)
} else {
console.error(err.message)
}
process.exit(1)
}
}
main()