@@ -7,7 +7,6 @@ import { DryRunEvent, UnsuccessfulWorkflowExecution } from '@angular-devkit/sche
77import { getCollection , getSchematic } from '../utilities/schematics' ;
88import { take } from 'rxjs/operators' ;
99import { WorkspaceLoader } from '../models/workspace-loader' ;
10- import chalk from 'chalk' ;
1110
1211export interface CoreSchematicOptions {
1312 dryRun : boolean ;
@@ -28,20 +27,11 @@ export interface GetOptionsOptions {
2827 schematicName : string ;
2928}
3029
31- export interface GetHelpOutputOptions {
32- collectionName : string ;
33- schematicName : string ;
34- nonSchematicOptions : any [ ] ;
30+ export interface GetOptionsResult {
31+ options : Option [ ] ;
32+ arguments : Option [ ] ;
3533}
3634
37- const hiddenOptions = [
38- 'name' ,
39- 'path' ,
40- 'source-dir' ,
41- 'app-root' ,
42- 'link-cli' ,
43- ] ;
44-
4535export abstract class SchematicCommand extends Command {
4636 readonly options : Option [ ] = [ ] ;
4737 private _host = new NodeJsSyncHost ( ) ;
@@ -185,7 +175,7 @@ export abstract class SchematicCommand extends Command {
185175 return opts ;
186176 }
187177
188- protected getOptions ( options : GetOptionsOptions ) : Promise < Option [ ] | null > {
178+ protected getOptions ( options : GetOptionsOptions ) : Promise < GetOptionsResult > {
189179 // TODO: get default collectionName
190180 const collectionName = options . collectionName || '@schematics/angular' ;
191181
@@ -195,7 +185,10 @@ export abstract class SchematicCommand extends Command {
195185 this . _deAliasedName = schematic . description . name ;
196186
197187 if ( ! schematic . description . schemaJson ) {
198- return Promise . resolve ( null ) ;
188+ return Promise . resolve ( {
189+ options : [ ] ,
190+ arguments : [ ]
191+ } ) ;
199192 }
200193
201194 const properties = schematic . description . schemaJson . properties ;
@@ -228,7 +221,6 @@ export abstract class SchematicCommand extends Command {
228221 if ( opt . aliases ) {
229222 aliases = [ ...aliases , ...opt . aliases ] ;
230223 }
231-
232224 const schematicDefault = opt . default ;
233225
234226 return {
@@ -243,54 +235,31 @@ export abstract class SchematicCommand extends Command {
243235 } )
244236 . filter ( x => x ) ;
245237
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' ) ;
252240
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 ;
290256 }
291-
292- return output ;
293257 } ) ;
258+
259+ return Promise . resolve ( {
260+ options : schematicOptions ,
261+ arguments : schematicArguments
262+ } ) ;
294263 }
295264
296265 private _loadWorkspace ( ) {
0 commit comments