8000 Merge pull request #1024 from telerik/vladimirov/fix-default-help · telerik/mobile-cli-lib@df4b878 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit df4b878

Browse files
Merge pull request #1024 from telerik/vladimirov/fix-default-help
Fix showing default help (from index.md)
2 parents c80e999 + b034b30 commit df4b878

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

services/help-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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 {

test/unit-tests/services/help-service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)
0