Skip to content

Commit

Permalink
Fix CLI options
Browse files Browse the repository at this point in the history
The way to get cli options changed at some point in the commander library.

Signed-off-by: Eher <alexandre@eher.com.br>
  • Loading branch information
EHER committed Sep 14, 2024
1 parent b42d51c commit 94adee0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <integer>",
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 94adee0

Please sign in to comment.