Skip to content

Commit

Permalink
fixup: sort negations correctly in --help output
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Jun 20, 2021
1 parent 3ccb0f8 commit 3d97be2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/internal/main/print_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
MathMax,
ObjectKeys,
RegExp,
StringPrototypeLocaleCompare,
StringPrototypeSlice,
StringPrototypeTrimLeft,
StringPrototypeRepeat,
Expand Down Expand Up @@ -111,9 +112,22 @@ function format(
let text = '';
let maxFirstColumnUsed = 0;

const sortedOptions = ArrayPrototypeSort(
[...options.entries()],
({ 0: name1, 1: option1 }, { 0: name2, 1: option2 }) => {
if (option1.defaultIsTrue) {
name1 = `--no-${StringPrototypeSlice(name1, 2)}`;
}
if (option2.defaultIsTrue) {
name2 = `--no-${StringPrototypeSlice(name2, 2)}`;
}
return StringPrototypeLocaleCompare(name1, name2);
},
);

for (const {
0: name, 1: { helpText, type, value, defaultIsTrue }
} of ArrayPrototypeSort([...options.entries()])) {
} of sortedOptions) {
if (!helpText) continue;

let displayName = name;
Expand Down

0 comments on commit 3d97be2

Please sign in to comment.