@@ -7,7 +7,6 @@ import { DryRunEvent, UnsuccessfulWorkflowExecution } from '@angular-devkit/sche
7
7
import { getCollection , getSchematic } from '../utilities/schematics' ;
8
8
import { take } from 'rxjs/operators' ;
9
9
import { WorkspaceLoader } from '../models/workspace-loader' ;
10
- import chalk from 'chalk' ;
11
10
12
11
export interface CoreSchematicOptions {
13
12
dryRun : boolean ;
@@ -28,20 +27,11 @@ export interface GetOptionsOptions {
28
27
schematicName : string ;
29
28
}
30
29
31
- export interface GetHelpOutputOptions {
32
- collectionName : string ;
33
- schematicName : string ;
34
- nonSchematicOptions : any [ ] ;
30
+ export interface GetOptionsResult {
31
+ options : Option [ ] ;
32
+ arguments : Option [ ] ;
35
33
}
36
34
37
- const hiddenOptions = [
38
- 'name' ,
39
- 'path' ,
40
- 'source-dir' ,
41
- 'app-root' ,
42
- 'link-cli' ,
43
- ] ;
44
-
45
35
export abstract class SchematicCommand extends Command {
46
36
readonly options : Option [ ] = [ ] ;
47
37
private _host = new NodeJsSyncHost ( ) ;
@@ -185,7 +175,7 @@ export abstract class SchematicCommand extends Command {
185
175
return opts ;
186
176
}
187
177
188
- protected getOptions ( options : GetOptionsOptions ) : Promise < Option [ ] | null > {
178
+ protected getOptions ( options : GetOptionsOptions ) : Promise < GetOptionsResult > {
189
179
// TODO: get default collectionName
190
180
const collectionName = options . collectionName || '@schematics/angular' ;
191
181
@@ -195,7 +185,10 @@ export abstract class SchematicCommand extends Command {
195
185
this . _deAliasedName = schematic . description . name ;
196
186
197
187
if ( ! schematic . description . schemaJson ) {
198
- return Promise . resolve ( null ) ;
188
+ return Promise . resolve ( {
189
+ options : [ ] ,
190
+ arguments : [ ]
191
+ } ) ;
199
192
}
200
193
201
194
const properties = schematic . description . schemaJson . properties ;
@@ -228,7 +221,6 @@ export abstract class SchematicCommand extends Command {
228
221
if ( opt . aliases ) {
229
222
aliases = [ ...aliases , ...opt . aliases ] ;
230
223
}
231
-
232
224
const schematicDefault = opt . default ;
233
225
234
226
return {
@@ -243,54 +235,31 @@ export abstract class SchematicCommand extends Command {
243
235
} )
244
236
. filter ( x => x ) ;
245
237
246
- return Promise . resolve ( availableOptions ) ;
247
- }
248
-
249
- protected getHelpOutput (
250
- { schematicName, collectionName, nonSchematicOptions } : GetHelpOutputOptions ) :
251
- Promise < string [ ] > {
238
+ const schematicOptions = availableOptions
239
+ . filter ( opt => opt . $default === undefined || opt . $default . $source !== 'argv' ) ;
252
240
253
- const SchematicGetOptionsTask = require ( './schematic-get-options' ) . default ;
254
- const getOptionsTask = new SchematicGetOptionsTask ( {
255
- ui : this . ui ,
256
- project : this . project
257
- } ) ;
258
- return Promise . all ( [ getOptionsTask . run ( {
259
- schematicName : schematicName ,
260
- collectionName : collectionName ,
261
- } ) , nonSchematicOptions ] )
262
- . then ( ( [ availableOptions , nonSchematicOptions ] : [ Option [ ] , any [ ] ] ) => {
263
- const output : string [ ] = [ ] ;
264
- [ ...( nonSchematicOptions || [ ] ) , ...availableOptions || [ ] ]
265
- . filter ( opt => hiddenOptions . indexOf ( opt . name ) === - 1 )
266
- . forEach ( opt => {
267
- let text = chalk . cyan ( ` --${ opt . name } ` ) ;
268
- if ( opt . schematicType ) {
269
- text += chalk . cyan ( ` (${ opt . schematicType } )` ) ;
270
- }
271
- if ( opt . schematicDefault ) {
272
- text += chalk . cyan ( ` (Default: ${ opt . schematicDefault } )` ) ;
273
- }
274
- if ( opt . description ) {
275
- text += ` ${ opt . description } ` ;
276
- }
277
- output . push ( text ) ;
278
- if ( opt . aliases && opt . aliases . length > 0 ) {
279
- const aliasText = opt . aliases . reduce (
280
- ( acc : string , curr : string ) => {
281
- return acc + ` -${ curr } ` ;
282
- } ,
283
- '' ) ;
284
- output . push ( chalk . grey ( ` aliases: ${ aliasText } ` ) ) ;
285
- }
286
- } ) ;
287
- if ( availableOptions === null ) {
288
- output . push ( chalk . green ( 'This schematic accept additional options, but did not provide '
289
- + 'documentation.' ) ) ;
241
+ const schematicArguments = availableOptions
242
+ . filter ( opt => opt . $default !== undefined && opt . $default . $source === 'argv' )
243
+ . sort ( ( a , b ) => {
244
+ if ( a . $default . index === undefined ) {
245
+ return 1 ;
246
+ }
247
+ if ( b . $default . index === undefined ) {
248
+ return - 1 ;
249
+ }
250
+ if ( a . $default . index == b . $default . index ) {
251
+ return 0 ;
252
+ } else if ( a . $default . index > b . $default . index ) {
253
+ return 1 ;
254
+ } else {
255
+ return - 1 ;
290
256
}
291
-
292
- return output ;
293
257
} ) ;
258
+
259
+ return Promise . resolve ( {
260
+ options : schematicOptions ,
261
+ arguments : schematicArguments
262
+ } ) ;
294
263
}
295
264
296
265
private _loadWorkspace ( ) {
0 commit comments