@@ -28,6 +28,38 @@ export class CommandLineConfiguration {
2828 public readonly commands : CommandJson [ ] = [ ] ;
2929 public readonly parameters : ParameterJson [ ] = [ ] ;
3030
31+ /**
32+ * Use CommandLineConfiguration.loadFromFile()
33+ */
34+ private constructor ( commandLineJson : ICommandLineJson | undefined ) {
35+ if ( commandLineJson ) {
36+ if ( commandLineJson . commands ) {
37+ for ( const command of commandLineJson . commands ) {
38+ this . commands . push ( command ) ;
39+ }
40+ }
41+
42+ if ( commandLineJson . parameters ) {
43+ for ( const parameter of commandLineJson . parameters ) {
44+ this . parameters . push ( parameter ) ;
45+
46+ // Do some basic validation
47+ switch ( parameter . parameterKind ) {
48+ case 'choice' :
49+ const alternativeNames : string [ ] = parameter . alternatives . map ( x => x . name ) ;
50+
51+ if ( parameter . defaultValue && alternativeNames . indexOf ( parameter . defaultValue ) < 0 ) {
52+ throw new Error ( `In ${ RushConstants . commandLineFilename } , the parameter "${ parameter . longName } ",`
53+ + ` specifies a default value "${ parameter . defaultValue } "`
54+ + ` which is not one of the defined alternatives: "${ alternativeNames . toString ( ) } "` ) ;
55+ }
56+ break ;
57+ }
58+ }
59+ }
60+ }
61+ }
62+
3163 /**
3264 * Loads the configuration from the specified file and applies any ommited default build
3365 * settings. If the file does not exist, then an empty default instance is returned.
@@ -88,36 +120,4 @@ export class CommandLineConfiguration {
88120
89121 return new CommandLineConfiguration ( commandLineJson ) ;
90122 }
91-
92- /**
93- * Use CommandLineConfiguration.loadFromFile()
94- */
95- private constructor ( commandLineJson : ICommandLineJson | undefined ) {
96- if ( commandLineJson ) {
97- if ( commandLineJson . commands ) {
98- for ( const command of commandLineJson . commands ) {
99- this . commands . push ( command ) ;
100- }
101- }
102-
103- if ( commandLineJson . parameters ) {
104- for ( const parameter of commandLineJson . parameters ) {
105- this . parameters . push ( parameter ) ;
106-
107- // Do some basic validation
108- switch ( parameter . parameterKind ) {
109- case 'choice' :
110- const alternativeNames : string [ ] = parameter . alternatives . map ( x => x . name ) ;
111-
112- if ( parameter . defaultValue && alternativeNames . indexOf ( parameter . defaultValue ) < 0 ) {
113- throw new Error ( `In ${ RushConstants . commandLineFilename } , the parameter "${ parameter . longName } ",`
114- + ` specifies a default value "${ parameter . defaultValue } "`
115- + ` which is not one of the defined alternatives: "${ alternativeNames . toString ( ) } "` ) ;
116- }
117- break ;
118- }
119- }
120- }
121- }
122- }
123123}
0 commit comments