@@ -62,7 +62,7 @@ export async function runCommand(commandMap: CommandMap,
62
62
args = [ 'help' ] ;
63
63
}
64
64
const rawOptions = yargsParser ( args , { alias : { help : [ 'h' ] } , boolean : [ 'help' ] } ) ;
65
- let commandName = rawOptions . _ [ 0 ] ;
65
+ let commandName = rawOptions . _ [ 0 ] || '' ;
66
66
67
67
// remove the command name
68
68
rawOptions . _ = rawOptions . _ . slice ( 1 ) ;
@@ -71,39 +71,48 @@ export async function runCommand(commandMap: CommandMap,
71
71
: CommandScope . outsideProject ;
72
72
73
73
let Cmd : CommandConstructor | null ;
74
- Cmd = findCommand ( commandMap , commandName ) ;
74
+ Cmd = commandName ? findCommand ( commandMap , commandName ) : null ;
75
75
76
- if ( ! Cmd && ! commandName && ( rawOptions . v || rawOptions . version ) ) {
76
+ if ( ! Cmd && ( rawOptions . v || rawOptions . version ) ) {
77
77
commandName = 'version' ;
78
78
Cmd = findCommand ( commandMap , commandName ) ;
79
- }
80
-
81
- if ( ! Cmd && rawOptions . help ) {
79
+ } else if ( ! Cmd && ( ! commandName || rawOptions . help ) ) {
82
80
commandName = 'help' ;
83
81
Cmd = findCommand ( commandMap , commandName ) ;
84
82
}
85
83
86
84
if ( ! Cmd ) {
87
- const commandsDistance = { } as { [ name : string ] : number } ;
88
- const allCommands = listAllCommandNames ( commandMap ) . sort ( ( a , b ) => {
89
- if ( ! ( a in commandsDistance ) ) {
90
- commandsDistance [ a ] = levenshtein ( a , commandName ) ;
91
- }
92
- if ( ! ( b in commandsDistance ) ) {
93
- commandsDistance [ b ] = levenshtein ( b , commandName ) ;
94
- }
85
+ if ( ! commandName ) {
86
+ logger . error ( tags . stripIndent `
87
+ We could not find a command from the arguments and the help command seems to be disabled.
88
+ This is an issue with the CLI itself. If you see this comment, please report it and
89
+ provide your repository.
90
+ ` ) ;
95
91
96
- return commandsDistance [ a ] - commandsDistance [ b ] ;
97
- } ) ;
92
+ return 1 ;
93
+ } else {
94
+ // Set name to string (no undefined).
95
+ const commandsDistance = { } as { [ name : string ] : number } ;
96
+ const allCommands = listAllCommandNames ( commandMap ) . sort ( ( a , b ) => {
97
+ if ( ! ( a in commandsDistance ) ) {
98
+ commandsDistance [ a ] = levenshtein ( a , commandName ) ;
99
+ }
100
+ if ( ! ( b in commandsDistance ) ) {
101
+ commandsDistance [ b ] = levenshtein ( b , commandName ) ;
102
+ }
103
+
104
+ return commandsDistance [ a ] - commandsDistance [ b ] ;
105
+ } ) ;
98
106
99
- logger . error ( tags . stripIndent `
107
+ logger . error ( tags . stripIndent `
100
108
The specified command ("${ commandName } ") is invalid. For a list of available options,
101
109
run "ng help".
102
110
103
111
Did you mean "${ allCommands [ 0 ] } "?
104
- ` ) ;
112
+ ` ) ;
105
113
106
- return 1 ;
114
+ return 1 ;
115
+ }
107
116
}
108
117
109
118
const command = new Cmd ( context , logger ) ;
0 commit comments