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); }