-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlo.js
executable file
·46 lines (40 loc) · 1.24 KB
/
lo.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
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const debug = require('debug')('lo');
const yargs = require('yargs');
// Needed because the cognito library tries to fetch the user-agent from the browser
global.navigator = () => null;
function handleError (msg, err) {
debug(`%j`, msg);
if (err && err.response) {
if (err.response.status === 401) {
console.log(`Security credentials do not exist or have expired. Use 'lo auth' to obtain new credentials.`);
} else {
console.log(chalk.red(`Request failed with status: ${err.response.status}, body:`));
console.log(chalk.red(JSON.stringify(err.response.data, null, 2)));
}
} else if (msg) {
console.error(chalk.red(msg));
} else {
console.error(chalk.red(err));
}
process.exitCode = 1;
}
// eslint-disable-next-line no-unused-expressions
yargs
.fail(handleError)
.commandDir('lib/cmds')
.scriptName('lo')
.demandCommand(1, 'You need at least one command before moving on')
.recommendCommands()
.help()
.argv;
process.on('uncaughtException', function (err) {
debug(`%j`, err);
console.error(err);
process.exitCode = 1;
});
process.on('unhandledRejection', function (reason, p) {
handleError(reason.toString(), reason);
});