Skip to content

Commit cff8c7c

Browse files
committed
auto-hide flags if there's an existing --no- variant
1 parent ffef644 commit cff8c7c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/cli/commands/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const create = new Command('create')
4343
.description('scaffolds a new SvelteKit project')
4444
.argument('[path]', 'where the project will be created', process.cwd())
4545
.addOption(templateOption)
46-
.addOption(new Option('--no-types').hideHelp())
4746
.addOption(langOption)
47+
.option('--no-types')
4848
.option('--no-integrations', 'skip interactive integration installer')
4949
.option('--no-install', 'skip installing dependencies')
5050
.configureHelp(common.helpConfig)

packages/cli/common.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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+
const NO_PREFIX = '--no-';
1112
let options: readonly Option[] = [];
1213

1314
function getLongFlag(flags: string) {
@@ -21,8 +22,23 @@ export const helpConfig: HelpConfiguration = {
2122
argumentDescription: formatDescription,
2223
optionDescription: formatDescription,
2324
visibleOptions(cmd) {
25+
// hack so that we can access existing options in `optionTerm`
2426
options = cmd.options;
25-
return cmd.options.filter((o) => !o.hidden);
27+
28+
const visible = cmd.options.filter((o) => !o.hidden);
29+
const show: Option[] = [];
30+
// hide any `--no-` flag variants if there's an existing flag of a similar name
31+
// e.g. `--types` and `--no-types` will combine into a single `--[no-]types` flag
32+
for (const option of visible) {
33+
const flag = getLongFlag(option.flags);
34+
if (flag?.startsWith(NO_PREFIX)) {
35+
const stripped = flag.slice(NO_PREFIX.length);
36+
const isNoVariant = visible.some((o) => getLongFlag(o.flags)?.startsWith(`--${stripped}`));
37+
if (isNoVariant) continue;
38+
}
39+
show.push(option);
40+
}
41+
return show;
2642
},
2743
optionTerm(option) {
2844
const longFlag = getLongFlag(option.flags);

0 commit comments

Comments
 (0)