@@ -8,6 +8,11 @@ import { POWERSHELL_DYNAMIC_HELPERS } from '../templates/powershell-templates.js
88export class PowerShellGenerator implements CompletionGenerator {
99 readonly shell = 'powershell' as const ;
1010
11+ private stripTrailingCommaFromLastLine ( lines : string [ ] ) : void {
12+ if ( lines . length === 0 ) return ;
13+ lines [ lines . length - 1 ] = lines [ lines . length - 1 ] . replace ( / , \s * $ / , '' ) ;
14+ }
15+
1116 /**
1217 * Generate a PowerShell completion script
1318 *
@@ -20,6 +25,7 @@ export class PowerShellGenerator implements CompletionGenerator {
2025 for ( const cmd of commands ) {
2126 commandLines . push ( ` @{Name="${ cmd . name } "; Description="${ this . escapeDescription ( cmd . description ) } "},` ) ;
2227 }
28+ this . stripTrailingCommaFromLastLine ( commandLines ) ;
2329 const topLevelCommands = commandLines . join ( '\n' ) ;
2430
2531 // Build command cases using push() for loop clarity
@@ -88,6 +94,7 @@ Register-ArgumentCompleter -CommandName openspec -ScriptBlock $openspecCompleter
8894 lines . push ( `${ indent } @{Name="${ longFlag } "; Description="${ this . escapeDescription ( flag . description ) } "},` ) ;
8995 }
9096 }
97+ this . stripTrailingCommaFromLastLine ( lines ) ;
9198 lines . push ( `${ indent } )` ) ;
9299 lines . push ( `${ indent } $flags | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {` ) ;
93100 lines . push ( `${ indent } [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, "ParameterName", $_.Description)` ) ;
@@ -103,6 +110,7 @@ Register-ArgumentCompleter -CommandName openspec -ScriptBlock $openspecCompleter
103110 for ( const subcmd of cmd . subcommands ) {
104111 lines . push ( `${ indent } @{Name="${ subcmd . name } "; Description="${ this . escapeDescription ( subcmd . description ) } "},` ) ;
105112 }
113+ this . stripTrailingCommaFromLastLine ( lines ) ;
106114 lines . push ( `${ indent } )` ) ;
107115 lines . push ( `${ indent } $subcommands | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {` ) ;
108116 lines . push ( `${ indent } [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, "ParameterValue", $_.Description)` ) ;
@@ -148,6 +156,7 @@ Register-ArgumentCompleter -CommandName openspec -ScriptBlock $openspecCompleter
148156 lines . push ( `${ indent } @{Name="${ longFlag } "; Description="${ this . escapeDescription ( flag . description ) } "},` ) ;
149157 }
150158 }
159+ this . stripTrailingCommaFromLastLine ( lines ) ;
151160 lines . push ( `${ indent } )` ) ;
152161 lines . push ( `${ indent } $flags | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {` ) ;
153162 lines . push ( `${ indent } [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, "ParameterName", $_.Description)` ) ;
0 commit comments