@@ -120,17 +120,27 @@ t.command('lint', 'Lint project').argument(
120120 true
121121) ; // Variadic argument for multiple files
122122
123+ const supportedShells = [ 'zsh' , 'bash' , 'fish' , 'powershell' ] ;
124+ const completeUsage =
125+ 'ERROR: Usage: vite complete <shell> | vite complete -- <argv>' ;
126+
127+ function printCompleteUsageAndExit ( ) {
128+ console . error ( completeUsage ) ;
129+ process . exit ( 1 ) ;
130+ }
131+
123132// Handle completion command
124133if ( process . argv [ 2 ] === 'complete' ) {
125- const shell = process . argv [ 3 ] ;
126- if ( shell && [ 'zsh' , 'bash' , 'fish' , 'powershell' ] . includes ( shell ) ) {
127- t . setup ( 'vite' , 'pnpm tsx examples/demo.t.ts' , shell ) ;
134+ const mode = process . argv [ 3 ] ;
135+
136+ if ( mode === '--' ) {
137+ // Runtime completion request from the generated shell script.
138+ t . parse ( process . argv . slice ( 4 ) ) ;
139+ } else if ( mode && supportedShells . includes ( mode ) ) {
140+ // Shell script generation.
141+ t . setup ( 'vite' , 'pnpm tsx examples/demo.t.ts' , mode ) ;
128142 } else {
129- // Parse completion arguments (everything after --)
130- const separatorIndex = process . argv . indexOf ( '--' ) ;
131- const completionArgs =
132- separatorIndex !== - 1 ? process . argv . slice ( separatorIndex + 1 ) : [ ] ;
133- t . parse ( completionArgs ) ;
143+ printCompleteUsageAndExit ( ) ;
134144 }
135145} else {
136146 // Regular CLI usage (just show help for demo)
0 commit comments