Skip to content

Commit 0e6a3c3

Browse files
committed
combine --no option variants
1 parent be6a076 commit 0e6a3c3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/cli/common.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,35 @@ import { COMMANDS, constructCommand, resolveCommand } from 'package-manager-dete
88
import type { Argument, HelpConfiguration, Option } from 'commander';
99
import type { AdderWithoutExplicitArgs, Precondition } from '@sveltejs/cli-core';
1010

11+
let options: readonly Option[] = [];
12+
13+
function getLongFlag(flags: string) {
14+
return flags
15+
.split(',')
16+
.map((f) => f.trim())
17+
.find((f) => f.startsWith('--'));
18+
}
19+
1120
export const helpConfig: HelpConfiguration = {
1221
argumentDescription: formatDescription,
13-
optionDescription: formatDescription
22+
optionDescription: formatDescription,
23+
visibleOptions(cmd) {
24+
options = cmd.options;
25+
return cmd.options.filter((o) => !o.hidden);
26+
},
27+
optionTerm(option) {
28+
const flag = getLongFlag(option.flags)?.split(' ').at(0);
29+
if (!flag) return option.flags;
30+
31+
// check if there's a `--no-{flag}` variant
32+
const noVariant = `--no-${flag.slice(2)}`;
33+
const hasVariant = options.some((o) => getLongFlag(o.flags) === noVariant);
34+
if (hasVariant) {
35+
return `--[no-]${flag.slice(2)}`;
36+
}
37+
38+
return option.flags;
39+
}
1440
};
1541

1642
function formatDescription(arg: Option | Argument): string {

0 commit comments

Comments
 (0)