Skip to content

Commit

Permalink
Fix: logging supplied & parsed arguments (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Jun 22, 2024
1 parent e0d3e21 commit 7c2c8cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 13 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ gracefulFs.gracefulify(realFs);
// Parse CLI arguments
let options: Options;
try {
options = new ArgumentsParser(logger).parse(process.argv.slice(2));
const argv = process.argv.slice(2);
options = new ArgumentsParser(logger).parse(argv);
logger.setLogLevel(options.getLogLevel());

const argvString = argv.map((arg) => {
if (!arg.includes(' ')) {
return arg;
}
return `"${arg.replace(/"/g, '\\"')}"`;
}).join(' ');
logger.trace(`Parsing CLI arguments: ${argvString}`);
logger.trace(`Parsed CLI options: ${options.toString()}`);

if (options.getHelp()) {
process.exit(0);
}
logger.setLogLevel(options.getLogLevel());
} catch (error) {
// Explicitly do not log the stack trace, for readability
logger.error(error);
Expand Down
13 changes: 1 addition & 12 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ export default class ArgumentsParser {
* Parse the arguments.
*/
parse(argv: string[]): Options {
const argvString = argv.map((arg) => {
if (!arg.includes(' ')) {
return arg;
}
return `"${arg.replace(/"/g, '\\"')}"`;
}).join(' ');
this.logger.trace(`Parsing CLI arguments: ${argvString}`);

const groupRomInput = 'ROM input options:';
const groupDatInput = 'DAT input options:';
const groupPatchInput = 'Patch input options:';
Expand Down Expand Up @@ -954,9 +946,6 @@ Example use cases:
}
});

const options = Options.fromObject(yargsArgv);
this.logger.trace(`Parsed options: ${options.toString()}`);

return options;
return Options.fromObject(yargsArgv);
}
}

0 comments on commit 7c2c8cf

Please sign in to comment.