From 283b7a03b0254f272eae290e7fdce39a716cf4d2 Mon Sep 17 00:00:00 2001 From: Mole Shang <135e2@135e2.dev> Date: Mon, 4 Sep 2023 12:53:41 +0800 Subject: load credentials.json from arg config path --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 53daae4..b02aedb 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,12 @@ const headers = { const flags = parse(Deno.args, { boolean: ["login", "logout"], - default: { login: true } + string: ["config"], + default: { login: true, config: "./credentials.json" } }); try { - const credentials = JSON.parse(await Deno.readTextFile("./credentials.json")); + const credentials = JSON.parse(await Deno.readTextFile(flags.config)); if (lodash.isEmpty(credentials.username) || lodash.isEmpty(credentials.password)) { throw "Invalid credentials! "; @@ -36,7 +37,7 @@ const headers = { if (err instanceof SyntaxError) { exitWithError("Parse json failed!"); } else if (err instanceof Deno.errors.NotFound) { - exitWithError("./credentials.json not found!") + exitWithError("credentials.json not found!") } else { console.error(`[ERROR]: ${err.toString()}`); -- cgit v1.2.3