From 94adee017e4a19d46228747a717425f43ac6a278 Mon Sep 17 00:00:00 2001 From: Eher Date: Sun, 15 Sep 2024 00:29:16 +0200 Subject: [PATCH] Fix CLI options The way to get cli options changed at some point in the commander library. Signed-off-by: Eher --- lib/cli.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 1bdc3aa..e754c5d 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -18,7 +18,8 @@ program. "-v, --version", "json code style version") .option("-f, --fix", - "fix json file") + "fix json file", + false) .option("-q, --quiet", "quiet mode") .option("-s, --spaces ", @@ -34,7 +35,7 @@ program.parse(process.argv); function parse(path) { getFiles(path).map(processFile); - !program.fix || console.log(fixedFiles); + !program.opts().fix || console.log(fixedFiles); if (errors.includes(true)) { process.exit(1); @@ -46,16 +47,16 @@ function parse(path) { function processFile(filePath) { try { const source = fs.readFileSync(filePath, "utf8"); - const indentation = parseInt(program.spaces); + const indentation = parseInt(program.opts().spaces, 10); const formatted = formatter.formatJson(source, indentation); - const fileWithErrors = showDiff(program.quiet, source, formatted, filePath); + const fileWithErrors = showDiff(program.opts().quiet, source, formatted, filePath); errors.push(fileWithErrors); - let fixedFile = fixJsonFile(program.fix, filePath, formatted); + let fixedFile = fixJsonFile(program.opts().fix, filePath, formatted); fixedFiles.push(fixedFile); } catch (e) { - if (typeof program.spaces != "number") { + if (isNaN(program.opts().spaces)) { console.log("-s / --spaces should receive integer as parameter"); process.exit(1); }