@@ -8,6 +8,7 @@ import { COMMANDS, constructCommand, resolveCommand } from 'package-manager-dete
8
8
import type { Argument , HelpConfiguration , Option } from 'commander' ;
9
9
import type { AdderWithoutExplicitArgs , Precondition } from '@sveltejs/cli-core' ;
10
10
11
+ const NO_PREFIX = '--no-' ;
11
12
let options : readonly Option [ ] = [ ] ;
12
13
13
14
function getLongFlag ( flags : string ) {
@@ -21,8 +22,23 @@ export const helpConfig: HelpConfiguration = {
21
22
argumentDescription : formatDescription ,
22
23
optionDescription : formatDescription ,
23
24
visibleOptions ( cmd ) {
25
+ // hack so that we can access existing options in `optionTerm`
24
26
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 ;
26
42
} ,
27
43
optionTerm ( option ) {
28
44
const longFlag = getLongFlag ( option . flags ) ;
0 commit comments