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 6be9cc5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 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();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Query Jackett for cross-seedable torrents",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\""
},
"bin": {
"cross-seed": "bin/cmd.js"
Expand Down

0 comments on commit 6be9cc5

Please sign in to comment.