/
run.ts
51 lines (47 loc) · 1.62 KB
/
run.ts
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
import { CliRepl, parseCliArgs, mapCliToDriver, USAGE } from './index';
import { generateUri } from '@mongosh/service-provider-server';
import path from 'path';
import os from 'os';
(async() => {
let repl;
try {
const options = parseCliArgs(process.argv);
const { version } = require('../package.json');
if (options.help) {
// eslint-disable-next-line no-console
console.log(USAGE);
} else if (options.version) {
// eslint-disable-next-line no-console
console.log(version);
} else {
if (process.execPath === process.argv[1]) {
// Remove the built-in Node.js listener that prints e.g. deprecation
// warnings in single-binary release mode.
process.removeAllListeners('warning');
}
// This is for testing under coverage, see the the comment in the tests
if (process.env.CLEAR_SIGINT_LISTENERS) {
process.removeAllListeners('SIGINT');
}
process.title = 'mongosh';
const driverOptions = mapCliToDriver(options);
const driverUri = generateUri(options);
const appname = `${process.title} ${version}`;
repl = new CliRepl({
shellCliOptions: options,
input: process.stdin,
output: process.stdout,
onExit: process.exit,
shellHomePath: path.join(os.homedir(), '.mongodb/mongosh/')
});
await repl.start(driverUri, { appName: appname, ...driverOptions });
}
} catch (e) {
// eslint-disable-next-line no-console
console.error(`${e.name}: ${e.message}`);
if (repl !== undefined) {
repl.bus.emit('mongosh:error', e);
}
process.exit(1);
}
})();