This repository was archived by the owner on Feb 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -119,19 +119,19 @@ export class HelpService implements IHelpService {
119
119
}
120
120
121
121
private async convertCommandNameToFileName ( commandName : string ) : Promise < string > {
122
- const defaultCommandMatch = commandName . match ( / ( \w + ?) \| \* / ) ;
122
+ const defaultCommandMatch = commandName && commandName . match ( / ( \w + ?) \| \* / ) ;
123
123
if ( defaultCommandMatch ) {
124
124
this . $logger . trace ( "Default command found. Replace current command name '%s' with '%s'." , commandName , defaultCommandMatch [ 1 ] ) ;
125
125
commandName = defaultCommandMatch [ 1 ] ;
126
126
}
127
127
128
128
const availableCommands = this . $injector . getRegisteredCommandsNames ( true ) . sort ( ) ;
129
129
this . $logger . trace ( "List of registered commands: %s" , availableCommands . join ( ", " ) ) ;
130
- if ( ! _ . includes ( availableCommands , commandName ) ) {
130
+ if ( commandName && ! _ . includes ( availableCommands , commandName ) ) {
131
131
this . $errors . failWithoutHelp ( "Unknown command '%s'. Try '$ %s help' for a full list of supported commands." , commandName , this . $staticConfig . CLIENT_NAME . toLowerCase ( ) ) ;
132
132
}
133
133
134
- return commandName . replace ( / \| / g, "-" ) || "index" ;
134
+ return ( commandName && commandName . replace ( / \| / g, "-" ) ) || "index" ;
135
135
}
136
136
137
137
private tryOpeningSelectedPage ( htmlPage : string ) : boolean {
Original file line number Diff line number Diff line change @@ -419,5 +419,20 @@ and another one`
419
419
const output = injector . resolve ( "logger" ) . output ;
420
420
assert . isTrue ( output . indexOf ( "bla param1 param2 end" ) >= 0 ) ;
421
421
} ) ;
422
+
423
+ _ . each ( [ "" , null , undefined ] , ( commandName : string ) => {
424
+ it ( "shows index help when command is not specified" , async ( ) => {
425
+ const injector = createTestInjector ( ) ;
426
+ injector . register ( "fs" , {
427
+ enumerateFilesInDirectorySync : ( path : string ) => [ "index.md" ] ,
428
+ readText : ( ) => "index data is read"
429
+ } ) ;
430
+
431
+ const helpService = injector . resolve < IHelpService > ( "helpService" ) ;
432
+ await helpService . showCommandLineHelp ( commandName ) ;
433
+ const output = injector . resolve ( "logger" ) . output ;
434
+ assert . isTrue ( output . indexOf ( "index data is read" ) >= 0 ) ;
435
+ } ) ;
436
+ } ) ;
422
437
} ) ;
423
438
} ) ;
You can’t perform that action at this time.
0 commit comments