add --exit-code, fixes #8

This commit is contained in:
silverwind 2018-10-15 06:52:37 +02:00
parent c95b1bdb6e
commit f25855ad79
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 14 additions and 1 deletions

@ -24,6 +24,7 @@ usage: updates [options]
-g, --greatest [<pkg,...>] Prefer greatest over latest version
-i, --include <pkg,...> Only include given packages
-e, --exclude <pkg,...> Exclude given packages
-E, --exit-code Exit with code 2 on outdated packages
-r, --registry <url> Use a custom registry
-f, --file <path> Use specified package.json file
-j, --json Output a JSON object

@ -13,6 +13,7 @@ const args = require("minimist")(process.argv.slice(2), {
"v", "version",
],
string: [
"E", "exit-code",
"f", "file",
"g", "greatest",
"p", "prerelease",
@ -24,6 +25,7 @@ const args = require("minimist")(process.argv.slice(2), {
alias: {
c: "color",
e: "exclude",
E: "exit-code",
f: "file",
g: "greatest",
h: "help",
@ -46,6 +48,7 @@ if (args.help) {
-g, --greatest [<pkg,...>] Prefer greatest over latest version
-i, --include <pkg,...> Only include given packages
-e, --exclude <pkg,...> Exclude given packages
-E, --exit-code Exit with code 2 on outdated packages
-r, --registry <url> Use a custom registry
-f, --file <path> Use specified package.json file
-j, --json Output a JSON object
@ -75,6 +78,11 @@ if (args["no-color"]) process.env.FORCE_COLOR = "0";
const greatest = parseMixedArg(args.greatest);
const prerelease = parseMixedArg(args.prerelease);
let exitCode = parseMixedArg(args["exit-code"]);
if (Array.isArray(exitCode) && exitCode.length) {
exitCode = true;
}
const registry = args.registry.endsWith("/") ? args.registry : args.registry + "/";
const packageFile = args.file || require("find-up").sync("package.json");
@ -206,7 +214,11 @@ function finish(obj, opts) {
}
}
process.exit(opts.exitCode || (output.error ? 1 : 0));
if (exitCode) {
process.exit(Object.keys(deps).length ? 2 : 0);
} else {
process.exit(opts.exitCode || (output.error ? 1 : 0));
}
}
function highlightDiff(a, b, added) {