Skip to content

Commit

Permalink
Error more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Jun 11, 2020
1 parent f0bf8da commit 8299b03
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
7 changes: 0 additions & 7 deletions .idea/jsLibraryMappings.xml

This file was deleted.

29 changes: 26 additions & 3 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const chalk = require("chalk");
const path = require("path");
const fs = require("fs");
const packageDotJson = require("../package.json");
const template = require("../config.template");
const main = require("../index");

function setConfig(fn) {
Expand Down Expand Up @@ -64,10 +65,32 @@ program
Object.keys(overrides).forEach((key) => {
if (overrides[key] === undefined) delete overrides[key];
});
console.log({ ...configFile, ...overrides });
const config = { ...configFile, ...overrides };
const emptyTemplate = Object.keys(template).reduce(
(acc, cur) => ({ ...acc, [cur]: undefined }),
{}
);
const config = { ...emptyTemplate, ...configFile, ...overrides };
const valid = Object.entries(emptyTemplate).reduce((acc, [k, v]) => {
if (v === undefined) {
console.error(chalk.red("Missing configuration item:"), k);
return false;
}
return acc;
}, true);

main(config);
if (!valid) {
console.error("Please specify the missing item(s) in");
console.error("a configuration file or as command-line options.");
console.error(
"For more information, run\n\n\tcross-seed search --help\n"
);
return;
}
try {
main(config);
} catch (e) {
console.error(chalk.bold.red(e.message));
}
});

program.parse();

0 comments on commit 8299b03

Please sign in to comment.