1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.loadConfig = exports.run = void 0;
|
4 | const ymir_1 = require("@fimbul/ymir");
|
5 | const fs = require("fs");
|
6 | const path = require("path");
|
7 | const debug = require("debug");
|
8 | const log = debug('wotan:cli');
|
9 | async function run(argv) {
|
10 | if (argv.length === 1 && /^(')?-(?:v|-version)\1$/.test(argv[0]))
|
11 | return console.log(require('../package.json').version);
|
12 | try {
|
13 | const config = await loadConfig('.');
|
14 | const args = (await Promise.resolve().then(() => require('./argparse'))).parseArguments(argv, config);
|
15 | if (!await (await Promise.resolve().then(() => require('./commands'))).runCommand(args, undefined, config))
|
16 | process.exitCode = 2;
|
17 | }
|
18 | catch (e) {
|
19 | console.error(e instanceof ymir_1.ConfigurationError ? e.message : e);
|
20 | process.exitCode = 1;
|
21 | }
|
22 | }
|
23 | exports.run = run;
|
24 | function loadConfig(dir) {
|
25 | const fileName = path.join(dir, '.fimbullinter.yaml');
|
26 | return new Promise((resolve) => {
|
27 | return fs.readFile(fileName, { encoding: 'utf8' }, (err, content) => {
|
28 | if (err) {
|
29 | log("Not using '%s': %s", fileName, err.code);
|
30 | return resolve({});
|
31 | }
|
32 | Promise.resolve().then(() => require('js-yaml')).then((yaml) => {
|
33 | try {
|
34 | resolve(yaml.load(content) || {});
|
35 | log("Using global options from '%s'", fileName);
|
36 | }
|
37 | catch (e) {
|
38 | log("Not using '%s': %s", fileName, e && e.message);
|
39 | resolve({});
|
40 | }
|
41 | });
|
42 | });
|
43 | });
|
44 | }
|
45 | exports.loadConfig = loadConfig;
|
46 | if (require.main === module) {
|
47 | log('CLI arguments: %O', process.argv);
|
48 | run(process.argv.slice(2));
|
49 | }
|
50 |
|
\ | No newline at end of file |