Skip to content

Commit

Permalink
fix: code repetition per code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Sep 29, 2022
1 parent 21fd4fd commit eb0c843
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ added:
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/44631
description: add support for default values in input `config`.
description: Add support for default values in input `config`.
- version:
- v18.7.0
- v16.17.0
Expand Down
18 changes: 10 additions & 8 deletions lib/internal/util/parse_args/parse_args.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,17 @@ const parseArgs = (config = kEmptyObject) => {

const defaultValue = objectGetOwn(optionConfig, 'default');
if (defaultValue !== undefined) {
if (optionType === 'string' && !multipleOption) {
validateString(defaultValue, `options.${longOption}.default`);
} else if (optionType === 'string' && multipleOption) {
validateStringArray(defaultValue, `options.${longOption}.default`);
} else if (optionType === 'boolean' && !multipleOption) {
validateBoolean(defaultValue, `options.${longOption}.default`);
} else if (optionType === 'boolean' && multipleOption) {
validateBooleanArray(defaultValue, `options.${longOption}.default`);
let validator;
switch (optionType) {
case 'string':
validator = multipleOption ? validateStringArray : validateString;
break;

case 'boolean':
validator = multipleOption ? validateBooleanArray : validateBoolean;
break;
}
validator(defaultValue, `options.${longOption}.default`);
}
}
);
Expand Down

0 comments on commit eb0c843

Please sign in to comment.