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 {
119119 }
120120
121121 private async convertCommandNameToFileName ( commandName : string ) : Promise < string > {
122- const defaultCommandMatch = commandName . match ( / ( \w + ?) \| \* / ) ;
122+ const defaultCommandMatch = commandName && commandName . match ( / ( \w + ?) \| \* / ) ;
123123 if ( defaultCommandMatch ) {
124124 this . $logger . trace ( "Default command found. Replace current command name '%s' with '%s'." , commandName , defaultCommandMatch [ 1 ] ) ;
125125 commandName = defaultCommandMatch [ 1 ] ;
126126 }
127127
128128 const availableCommands = this . $injector . getRegisteredCommandsNames ( true ) . sort ( ) ;
129129 this . $logger . trace ( "List of registered commands: %s" , availableCommands . join ( ", " ) ) ;
130- if ( ! _ . includes ( availableCommands , commandName ) ) {
130+ if ( commandName && ! _ . includes ( availableCommands , commandName ) ) {
131131 this . $errors . failWithoutHelp ( "Unknown command '%s'. Try '$ %s help' for a full list of supported commands." , commandName , this . $staticConfig . CLIENT_NAME . toLowerCase ( ) ) ;
132132 }
133133
134- return commandName . replace ( / \| / g, "-" ) || "index" ;
134+ return ( commandName && commandName . replace ( / \| / g, "-" ) ) || "index" ;
135135 }
136136
137137 private tryOpeningSelectedPage ( htmlPage : string ) : boolean {
Original file line number Diff line number Diff line change @@ -419,5 +419,20 @@ and another one`
419419 const output = injector . resolve ( "logger" ) . output ;
420420 assert . isTrue ( output . indexOf ( "bla param1 param2 end" ) >= 0 ) ;
421421 } ) ;
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+ } ) ;
422437 } ) ;
423438} ) ;
You can’t perform that action at this time.
0 commit comments