44import path from 'node:path' ;
55import { JsonFile } from '@rushstack/node-core-library' ;
66import { ConsoleTerminalProvider , Terminal } from '@rushstack/terminal' ;
7- import {
8- CommandLineAction ,
9- type CommandLineParameter ,
10- type CommandLineFlagParameter ,
11- type CommandLineStringParameter ,
12- type CommandLineChoiceParameter ,
13- type CommandLineStringListParameter
14- } from '@rushstack/ts-command-line' ;
7+ import { CommandLineAction , type CommandLineParameter } from '@rushstack/ts-command-line' ;
158
169import { RushConfiguration } from '../../../api/RushConfiguration' ;
17- import { CommandLineConfiguration , type IPhasedCommandConfig } from '../../../api/CommandLineConfiguration' ;
10+ import {
11+ CommandLineConfiguration ,
12+ type IPhasedCommandConfig ,
13+ type IParameterJson ,
14+ type IPhase
15+ } from '../../../api/CommandLineConfiguration' ;
1816import type { Operation } from '../Operation' ;
1917import type { ICommandLineJson } from '../../../api/CommandLineJson' ;
2018import { PhasedOperationPlugin } from '../PhasedOperationPlugin' ;
@@ -24,7 +22,8 @@ import {
2422 PhasedCommandHooks
2523} from '../../../pluginFramework/PhasedCommandHooks' ;
2624import { RushProjectConfiguration } from '../../../api/RushProjectConfiguration' ;
27- import { createCommandLineParameters } from '../../../utilities/CommandLineParameterHelpers' ;
25+ import { defineCustomParameters } from '../../../cli/parsing/defineCustomParameters' ;
26+ import { associateParametersByPhase } from '../../../cli/parsing/associateParametersByPhase' ;
2827
2928interface ISerializedOperation {
3029 name : string ;
@@ -174,48 +173,58 @@ describe(ShellOperationRunnerPlugin.name, () => {
174173 } ) ;
175174
176175 // Create CommandLineParameter instances from the parameter definitions
177- const customParametersMap : Map < string , CommandLineParameter > = createCommandLineParameters (
178- action ,
179- buildCommand . associatedParameters
180- ) ;
176+ const customParametersMap : Map < IParameterJson , CommandLineParameter > = new Map ( ) ;
177+ defineCustomParameters ( action , buildCommand . associatedParameters , customParametersMap ) ;
181178
182179 // Set values on the parameters to test filtering
180+ // Create a map by longName for easier lookup
181+ const paramsByLongName : Map < string , { param : IParameterJson ; cli : CommandLineParameter } > = new Map ( ) ;
182+ for ( const [ param , cli ] of customParametersMap ) {
183+ paramsByLongName . set ( param . longName , { param, cli } ) ;
184+ }
185+
183186 // Set --production flag
184- const productionParam = customParametersMap . get ( '--production' ) as CommandLineFlagParameter | undefined ;
185- if ( productionParam ) {
186- ( productionParam as unknown as { _setValue ( value : boolean ) : void } ) . _setValue ( true ) ;
187+ const production = paramsByLongName . get ( '--production' ) ;
188+ if ( production ) {
189+ ( production . cli as unknown as { _setValue ( value : boolean ) : void } ) . _setValue ( true ) ;
187190 }
188191
189192 // Set --verbose flag
190- const verboseParam = customParametersMap . get ( '--verbose' ) as CommandLineFlagParameter | undefined ;
191- if ( verboseParam ) {
192- ( verboseParam as unknown as { _setValue ( value : boolean ) : void } ) . _setValue ( true ) ;
193+ const verbose = paramsByLongName . get ( '--verbose' ) ;
194+ if ( verbose ) {
195+ ( verbose . cli as unknown as { _setValue ( value : boolean ) : void } ) . _setValue ( true ) ;
193196 }
194197
195198 // Set --config parameter
196- const configParam = customParametersMap . get ( '--config' ) as CommandLineStringParameter | undefined ;
197- if ( configParam ) {
198- ( configParam as unknown as { _setValue ( value : string ) : void } ) . _setValue ( '/path/to/config.json' ) ;
199+ const config = paramsByLongName . get ( '--config' ) ;
200+ if ( config ) {
201+ ( config . cli as unknown as { _setValue ( value : string ) : void } ) . _setValue ( '/path/to/config.json' ) ;
199202 }
200203
201204 // Set --mode parameter
202- const modeParam = customParametersMap . get ( '--mode' ) as CommandLineChoiceParameter | undefined ;
203- if ( modeParam ) {
204- ( modeParam as unknown as { _setValue ( value : string ) : void } ) . _setValue ( 'prod' ) ;
205+ const mode = paramsByLongName . get ( '--mode' ) ;
206+ if ( mode ) {
207+ ( mode . cli as unknown as { _setValue ( value : string ) : void } ) . _setValue ( 'prod' ) ;
205208 }
206209
207210 // Set --tags parameter
208- const tagsParam = customParametersMap . get ( '--tags' ) as CommandLineStringListParameter | undefined ;
209- if ( tagsParam ) {
210- ( tagsParam as unknown as { _setValue ( value : string [ ] ) : void } ) . _setValue ( [ 'tag1' , 'tag2' ] ) ;
211+ const tags = paramsByLongName . get ( '--tags' ) ;
212+ if ( tags ) {
213+ ( tags . cli as unknown as { _setValue ( value : string [ ] ) : void } ) . _setValue ( [ 'tag1' , 'tag2' ] ) ;
211214 }
212215
213- // Update the phase's associatedParameters to use our created CommandLineParameters
216+ // Associate parameters with phases using the helper
217+ // Create a map of phase names to phases for the helper
218+ const phasesMap : Map < string , IPhase > = new Map ( ) ;
214219 for ( const phase of buildCommand . phases ) {
215- phase . associatedParameters . clear ( ) ;
216- for ( const param of customParametersMap . values ( ) ) {
217- phase . associatedParameters . add ( param ) ;
218- }
220+ phasesMap . set ( phase . name , phase ) ;
221+ }
222+ associateParametersByPhase ( customParametersMap , phasesMap ) ;
223+
224+ // Create customParameters map for ICreateOperationsContext (keyed by longName)
225+ const customParametersForContext : Map < string , CommandLineParameter > = new Map ( ) ;
226+ for ( const [ param , cli ] of customParametersMap ) {
227+ customParametersForContext . set ( param . longName , cli ) ;
219228 }
220229
221230 const fakeCreateOperationsContext : Pick <
@@ -234,7 +243,7 @@ describe(ShellOperationRunnerPlugin.name, () => {
234243 projectsInUnknownState : new Set ( rushConfiguration . projects ) ,
235244 projectConfigurations,
236245 rushConfiguration,
237- customParameters : customParametersMap
246+ customParameters : customParametersForContext
238247 } ;
239248
240249 const hooks : PhasedCommandHooks = new PhasedCommandHooks ( ) ;
0 commit comments