From 8c0b8cda0afd8988812792206afcff7523ecf165 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 3 Nov 2017 00:32:07 +0200 Subject: [PATCH] Do not track help command when other command fails In case any command fails, we execute help command in order to show the help content. This leads to multiple trackings, i.e. - user executes only one command, but in Analytics we see two commands. Instead of executing help command, introduce new method in htmlHelpService, that prints the help to the terminal and call it instead. Use the same method in the help command itself. Rename htmlHelpService to helpService - it has been incorrectly named from the beginning. Remove `helpTextPath` from staticConfig interface - this property is not used for more than 2 years. Introduce tests for `helpService` - get the tests from AppBuilder CLI. --- lib/commands/generate-help.ts | 4 ++-- lib/commands/post-install.ts | 4 ++-- lib/common | 2 +- lib/config.ts | 4 ---- test/commands/post-install.ts | 2 +- test/platform-commands.ts | 5 ++++- test/platform-service.ts | 3 +++ test/plugins-service.ts | 3 +++ test/stubs.ts | 2 +- 9 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/commands/generate-help.ts b/lib/commands/generate-help.ts index 71cfa998d4..18fc8af9a0 100644 --- a/lib/commands/generate-help.ts +++ b/lib/commands/generate-help.ts @@ -1,10 +1,10 @@ export class GenerateHelpCommand implements ICommand { public allowedParameters: ICommandParameter[] = []; - constructor(private $htmlHelpService: IHtmlHelpService) { } + constructor(private $helpService: IHelpService) { } public async execute(args: string[]): Promise { - return this.$htmlHelpService.generateHtmlPages(); + return this.$helpService.generateHtmlPages(); } } diff --git a/lib/commands/post-install.ts b/lib/commands/post-install.ts index 779703e5c3..f574171789 100644 --- a/lib/commands/post-install.ts +++ b/lib/commands/post-install.ts @@ -5,12 +5,12 @@ export class PostInstallCliCommand extends PostInstallCommand { private $subscriptionService: ISubscriptionService, $staticConfig: Config.IStaticConfig, $commandsService: ICommandsService, - $htmlHelpService: IHtmlHelpService, + $helpService: IHelpService, $options: ICommonOptions, $doctorService: IDoctorService, $analyticsService: IAnalyticsService, $logger: ILogger) { - super($fs, $staticConfig, $commandsService, $htmlHelpService, $options, $doctorService, $analyticsService, $logger); + super($fs, $staticConfig, $commandsService, $helpService, $options, $doctorService, $analyticsService, $logger); } public async execute(args: string[]): Promise { diff --git a/lib/common b/lib/common index 0812ce953f..06d4f68052 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 0812ce953f66e3f749f541b1e93af2794e40e866 +Subproject commit 06d4f680523cf79ecc7df47feeb61cf6acc7a2a7 diff --git a/lib/config.ts b/lib/config.ts index 4b6b21c942..dd4fcc8d13 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -60,10 +60,6 @@ export class StaticConfig extends StaticConfigBase implements IStaticConfig { public version = require("../package.json").version; - public get helpTextPath(): string { - return path.join(__dirname, "../resources/help.txt"); - } - public get HTML_CLI_HELPERS_DIR(): string { return path.join(__dirname, "../docs/helpers"); } diff --git a/test/commands/post-install.ts b/test/commands/post-install.ts index 5cadda5c0b..51f4dd8e02 100644 --- a/test/commands/post-install.ts +++ b/test/commands/post-install.ts @@ -18,7 +18,7 @@ const createTestInjector = (): IInjector => { tryExecuteCommand: async (commandName: string, commandArguments: string[]): Promise => undefined }); - testInjector.register("htmlHelpService", { + testInjector.register("helpService", { generateHtmlPages: async (): Promise => undefined }); diff --git a/test/platform-commands.ts b/test/platform-commands.ts index c14ce1cbd1..2a08302440 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -54,7 +54,7 @@ class ErrorsNoFailStub implements IErrors { throw new Error(); } - async beginCommand(action: () => Promise, printHelpCommand: () => Promise): Promise { + async beginCommand(action: () => Promise, printHelpCommand: () => Promise): Promise { let result = false; try { result = await action(); @@ -148,6 +148,9 @@ function createTestInjector() { }); testInjector.register("messages", Messages); testInjector.register("devicePathProvider", {}); + testInjector.register("helpService", { + showCommandLineHelp: async (): Promise => (undefined) + }); return testInjector; } diff --git a/test/platform-service.ts b/test/platform-service.ts index 4caf8b8992..1db73a785b 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -91,6 +91,9 @@ function createTestInjector() { }); testInjector.register("messages", Messages); testInjector.register("devicePathProvider", {}); + testInjector.register("helpService", { + showCommandLineHelp: async (): Promise => (undefined) + }); return testInjector; } diff --git a/test/plugins-service.ts b/test/plugins-service.ts index 6360e2ee0d..1f5953cec1 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -98,6 +98,9 @@ function createTestInjector() { }); testInjector.register("xmlValidator", XmlValidator); testInjector.register("config", StaticConfigLib.Configuration); + testInjector.register("helpService", { + showCommandLineHelp: async (): Promise => (undefined) + }); return testInjector; } diff --git a/test/stubs.ts b/test/stubs.ts index 5d45aa8dc9..f92ea63a1c 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -197,7 +197,7 @@ export class ErrorsStub implements IErrors { throw new Error(message); } - async beginCommand(action: () => Promise, printHelpCommand: () => Promise): Promise { + async beginCommand(action: () => Promise, printHelpCommand: () => Promise): Promise { throw new Error("not supported"); }