1
+ import chalk from 'chalk' ;
1
2
import * as fs from 'fs' ;
2
3
import * as path from 'path' ;
3
4
5
+ const { cyan } = chalk ;
4
6
const Command = require ( '../ember-cli/lib/models/command' ) ;
5
7
const stringUtils = require ( 'ember-cli-string-utils' ) ;
6
8
const lookupCommand = require ( '../ember-cli/lib/cli/lookup-command' ) ;
@@ -10,19 +12,11 @@ const HelpCommand = Command.extend({
10
12
description : 'Shows help for the CLI.' ,
11
13
works : 'everywhere' ,
12
14
13
- availableOptions : [
14
- {
15
- name : 'short' ,
16
- type : Boolean ,
17
- default : false ,
18
- aliases : [ 's' ] ,
19
- description : 'Display command name and description only.'
20
- } ,
21
- ] ,
15
+ availableOptions : [ ] ,
22
16
23
- anonymousOptions : [ 'command-name (Default: all)' ] ,
17
+ anonymousOptions : [ ] ,
24
18
25
- run : function ( commandOptions : any , rawArgs : any ) {
19
+ run : function ( _commandOptions : any , _rawArgs : any ) {
26
20
let commandFiles = fs . readdirSync ( __dirname )
27
21
// Remove files that are not JavaScript or Typescript
28
22
. filter ( file => file . match ( / \. ( j | t ) s $ / ) && ! file . match ( / \. d .t s $ / ) )
@@ -38,54 +32,26 @@ const HelpCommand = Command.extend({
38
32
return acc ;
39
33
} , { } ) ;
40
34
41
- if ( rawArgs . indexOf ( 'all' ) !== - 1 ) {
42
- rawArgs = [ ] ; // just act as if command not specified
43
- }
44
-
45
- commandFiles . forEach ( cmd => {
46
- const Command = lookupCommand ( commandMap , cmd ) ;
47
-
48
- const command = new Command ( {
49
- ui : this . ui ,
50
- project : this . project ,
51
- commands : this . commands ,
52
- tasks : this . tasks
53
- } ) ;
54
-
55
- if ( command . hidden || command . unknown ) {
56
- return ;
57
- }
58
-
59
- if ( rawArgs . length > 0 ) {
60
- let commandInput = rawArgs [ 0 ] ;
61
- const aliases = Command . prototype . aliases ;
62
- if ( aliases && aliases . indexOf ( commandInput ) > - 1 ) {
63
- commandInput = Command . prototype . name ;
64
- }
65
-
66
- if ( cmd === commandInput ) {
67
- if ( commandOptions . short ) {
68
- this . ui . writeLine ( command . printShortHelp ( commandOptions ) ) ;
69
- } else if ( command . printDetailedHelp ( commandOptions , rawArgs ) ) {
70
- const result = command . printDetailedHelp ( commandOptions , rawArgs ) ;
71
- if ( result instanceof Promise ) {
72
- result . then ( r => this . ui . writeLine ( r ) ) ;
73
- } else {
74
- this . ui . writeLine ( result ) ;
75
- }
76
- } else {
77
- this . ui . writeLine ( command . printBasicHelp ( commandOptions ) ) ;
78
- }
79
- }
80
- } else {
81
- if ( commandOptions . short ) {
82
- this . ui . writeLine ( command . printShortHelp ( commandOptions ) ) ;
83
- } else {
84
- this . ui . writeLine ( command . printBasicHelp ( commandOptions ) ) ;
85
- }
86
- }
87
-
35
+ const commands = commandFiles
36
+ . map ( commandFile => {
37
+ const Command = lookupCommand ( commandMap , commandFile ) ;
38
+
39
+ const cmd = new Command ( {
40
+ ui : this . ui ,
41
+ project : this . project ,
42
+ commands : this . commands ,
43
+ tasks : this . tasks
44
+ } ) ;
45
+
46
+ return cmd ;
47
+ } )
48
+ . filter ( cmd => ! cmd . hidden && ! cmd . unknown )
49
+ . map ( cmd => ( { name : cmd . name , description : cmd . description } ) ) ;
50
+ this . ui . writeLine ( `Available Commands:` ) ;
51
+ commands . forEach ( cmd => {
52
+ this . ui . writeLine ( ` ${ cyan ( cmd . name ) } ${ cmd . description } ` ) ;
88
53
} ) ;
54
+ this . ui . writeLine ( `\nFor more detailed help run "ng [command name] --help"` ) ;
89
55
}
90
56
} ) ;
91
57
0 commit comments