Skip to content

Commit 3d97be2

Browse files
committed
fixup: sort negations correctly in --help output
1 parent 3ccb0f8 commit 3d97be2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/internal/main/print_help.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
MathMax,
99
ObjectKeys,
1010
RegExp,
11+
StringPrototypeLocaleCompare,
1112
StringPrototypeSlice,
1213
StringPrototypeTrimLeft,
1314
StringPrototypeRepeat,
@@ -111,9 +112,22 @@ function format(
111112
let text = '';
112113
let maxFirstColumnUsed = 0;
113114

115+
const sortedOptions = ArrayPrototypeSort(
116+
[...options.entries()],
117+
({ 0: name1, 1: option1 }, { 0: name2, 1: option2 }) => {
118+
if (option1.defaultIsTrue) {
119+
name1 = `--no-${StringPrototypeSlice(name1, 2)}`;
120+
}
121+
if (option2.defaultIsTrue) {
122+
name2 = `--no-${StringPrototypeSlice(name2, 2)}`;
123+
}
124+
return StringPrototypeLocaleCompare(name1, name2);
125+
},
126+
);
127+
114128
for (const {
115129
0: name, 1: { helpText, type, value, defaultIsTrue }
116-
} of ArrayPrototypeSort([...options.entries()])) {
130+
} of sortedOptions) {
117131
if (!helpText) continue;
118132

119133
let displayName = name;

0 commit comments

Comments
 (0)