-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
executable file
·40 lines (33 loc) · 835 Bytes
/
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
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const pkg = require('./package.json');
const alias = { h: 'help', v: 'version' };
const usage = chalk`
{bold $0} v${pkg.version} - {yellow ${pkg.description}}
Usage:
$0 <command>`;
const footer = chalk`
Homepage: {green ${pkg.homepage}}
Report issue: {green ${pkg.bugs.url}}`.trim();
// eslint-disable-next-line no-unused-expressions
require('yargs')
.strict()
.alias(alias)
.commandDir('commands')
.demandCommand(1, '\nYou need at least one command before moving on')
.recommendCommands()
.fail(onError)
.usage(usage)
.epilogue(footer)
.help()
.argv;
function onError(msg, err, yargs) {
if (err) {
console.error(err);
process.exit(1);
}
yargs.showHelp();
if (msg) console.error(chalk.bold(msg));
process.exit(1);
}