Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI options #172

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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