Skip to content

Commit 1bad9c1

Browse files
committed
address review comments
1 parent 87e3190 commit 1bad9c1

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

cli/util/options.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface Result {
4242
}
4343

4444
/** Parses the specified command line arguments according to the given configuration. */
45-
export function parse(argv: string[], config: Config, populateDefaults?: boolean): Result;
45+
export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result;
4646

4747
/** Help formatting options. */
4848
interface HelpOptions {
@@ -57,8 +57,8 @@ interface HelpOptions {
5757
/** Generates the help text for the specified configuration. */
5858
export function help(config: Config, options?: HelpOptions): string;
5959

60+
/** Merges two sets of options into one, preferring the current over the parent set. */
61+
export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet): OptionSet;
62+
6063
/** Populates default values on a parsed options result. */
6164
export function addDefaults(config: Config, options: OptionSet): OptionSet;
62-
63-
/** Merges two sets of options into one, preferring the newer set. */
64-
export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet): OptionSet;

cli/util/options.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const colorsUtil = require("./colors");
1616
// S | string array
1717

1818
/** Parses the specified command line arguments according to the given configuration. */
19-
function parse(argv, config, populateDefaults = true) {
19+
function parse(argv, config, propagateDefaults = true) {
2020
var options = {};
2121
var unknown = [];
2222
var args = [];
@@ -87,7 +87,7 @@ function parse(argv, config, populateDefaults = true) {
8787
} else unknown.push(arg);
8888
}
8989
while (i < k) trailing.push(argv[i++]); // trailing
90-
if (populateDefaults) addDefaults(config, options);
90+
if (propagateDefaults) addDefaults(config, options);
9191

9292
return { options, unknown, arguments: args, trailing };
9393
}
@@ -149,13 +149,9 @@ function merge(config, currentOptions, parentOptions) {
149149
if (parentOptions[key] != null) {
150150
// only parent value present
151151
if (Array.isArray(parentOptions[key])) {
152-
if (mutuallyExclusive) {
153-
const exclude = currentOptions[mutuallyExclusive];
154-
if (exclude) {
155-
mergedOptions[key] = parentOptions[key].filter(value => !exclude.includes(value));
156-
} else {
157-
mergedOptions[key] = parentOptions[key].slice();
158-
}
152+
let exclude;
153+
if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
154+
mergedOptions[key] = parentOptions[key].filter(value => !exclude.includes(value));
159155
} else {
160156
mergedOptions[key] = parentOptions[key].slice();
161157
}
@@ -173,19 +169,12 @@ function merge(config, currentOptions, parentOptions) {
173169
} else {
174170
// both current and parent values present
175171
if (Array.isArray(currentOptions[key])) {
176-
if (mutuallyExclusive) {
177-
const exclude = currentOptions[mutuallyExclusive];
178-
if (exclude) {
179-
mergedOptions[key] = [
180-
...currentOptions[key],
181-
...parentOptions[key].filter(value => !currentOptions[key].includes(value) && !exclude.includes(value))
182-
];
183-
} else {
184-
mergedOptions[key] = [
185-
...currentOptions[key],
186-
...parentOptions[key].filter(value => !currentOptions[key].includes(value)) // dedup
187-
];
188-
}
172+
let exclude;
173+
if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
174+
mergedOptions[key] = [
175+
...currentOptions[key],
176+
...parentOptions[key].filter(value => !currentOptions[key].includes(value) && !exclude.includes(value))
177+
];
189178
} else {
190179
mergedOptions[key] = [
191180
...currentOptions[key],

0 commit comments

Comments
 (0)