From d982c346aec4ae6cd5be07b4e5935557968ca2ba Mon Sep 17 00:00:00 2001 From: Ashton Eby Date: Tue, 26 Nov 2024 08:44:36 -0800 Subject: [PATCH] add logging for completions --- src/cli.mjs | 15 ++++++++------- src/lib/completions.mjs | 6 ------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/cli.mjs b/src/cli.mjs index e589d38e..0157badd 100644 --- a/src/cli.mjs +++ b/src/cli.mjs @@ -110,21 +110,22 @@ function buildYargs(argvInput) { .strict(true) .completion( "completion", - function (currentWord, argv, completionFilter, done) { + function (currentWord, argv, defaultCompletions, done) { + const logger = container.resolve("logger"); const previousWord = process.argv.slice(-2, -1)[0].replace(/-/g, ""); const currentWordFlag = Object.keys(argv) .filter((key) => previousWord === key) .pop(); - // console.log("currentWord", currentWord); - // console.log("previousWord", previousWord); - // console.log("argv", JSON.stringify(argv, null, 2)); - // console.log("currentWordFlag", currentWordFlag); + logger.debug( + `Parsing completions with current word ${currentWord} (for flag ${currentWordFlag}) and previous word ${previousWord}.`, + "completion", + ); // TODO: this doesn't handle aliasing, and it needs to if (currentWord === "--dir" || currentWordFlag === "dir") { getDirCompletions(currentWord, done); } else { - completionFilter(); + defaultCompletions(); } }, ) @@ -163,7 +164,7 @@ function buildYargs(argvInput) { "components to emit diagnostic logs for; this takes precedence over the 'verbosity' flag", type: "array", default: [], - choices: ["fetch", "error", "argv"], + choices: ["fetch", "error", "argv", "completion"], }, // Whether authNZ middleware should run. Better way of doing this? authRequired: { diff --git a/src/lib/completions.mjs b/src/lib/completions.mjs index 5420209d..2b054f3d 100644 --- a/src/lib/completions.mjs +++ b/src/lib/completions.mjs @@ -54,12 +54,6 @@ function getDirInfo(possiblePath) { } export function getDirCompletions(currentWord, done) { - // console.log("currentWord", currentWord); - // console.log("previousWord", previousWord); - // console.log("argv", JSON.stringify(argv, null, 2)); - // console.log("matchKey", matchKey); - // console.log("matchValue", matchValue); - // console.log("dirs", dirs); done( getFSCompletions({ currentWord,