8000 Fix showing default help (from index.md) by rosen-vladimirov · Pull Request #1024 · telerik/mobile-cli-lib · 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.

Fix showing default help (from index.md) #1024

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions services/help-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ export class HelpService implements IHelpService {
}

private async convertCommandNameToFileName(commandName: string): Promise<string> {
const defaultCommandMatch = commandName.match(/(\w+?)\|\*/);
const defaultCommandMatch = commandName && commandName.match(/(\w+?)\|\*/);
if (defaultCommandMatch) {
this.$logger.trace("Default command found. Replace current command name '%s' with '%s'.", commandName, defaultCommandMatch[1]);
commandName = defaultCommandMatch[1];
}

const availableCommands = this.$injector.getRegisteredCommandsNames(true).sort();
this.$logger.trace("List of registered commands: %s", availableCommands.join(", "));
if (!_.includes(availableCommands, commandName)) {
if (commandName && !_.includes(availableCommands, commandName)) {
this.$errors.failWithoutHelp("Unknown command '%s'. Try '$ %s help' for a full list of supported commands.", commandName, this.$staticConfig.CLIENT_NAME.toLowerCase());
}

return commandName.replace(/\|/g, "-") || "index";
return (commandName && commandName.replace(/\|/g, "-")) || "index";
}

private tryOpeningSelectedPage(htmlPage: string): boolean {
Expand Down
15 changes: 15 additions & 0 deletions test/unit-tests/services/help-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,20 @@ and another one`
const output = injector.resolve("logger").output;
assert.isTrue(output.indexOf("bla param1 param2 end") >= 0);
});

_.each(["", null, undefined], (commandName: string) => {
it("shows index help when command is not specified", async () => {
const injector = createTestInjector();
injector.register("fs", {
enumerateFilesInDirectorySync: (path: string) => ["index.md"],
readText: () => "index data is read"
});

const helpService = injector.resolve<IHelpService>("helpService");
await helpService.showCommandLineHelp(commandName);
const output = injector.resolve("logger").output;
assert.isTrue(output.indexOf("index data is read") >= 0);
});
});
});
});
0