Skip to content

Commit 64cf9c4

Browse files
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.
1 parent ef45805 commit 64cf9c4

9 files changed

+17
-12
lines changed

lib/commands/generate-help.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export class GenerateHelpCommand implements ICommand {
22
public allowedParameters: ICommandParameter[] = [];
33

4-
constructor(private $htmlHelpService: IHtmlHelpService) { }
4+
constructor(private $helpService: IHelpService) { }
55

66
public async execute(args: string[]): Promise<void> {
7-
return this.$htmlHelpService.generateHtmlPages();
7+
return this.$helpService.generateHtmlPages();
88
}
99
}
1010

lib/commands/post-install.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export class PostInstallCliCommand extends PostInstallCommand {
55
private $subscriptionService: ISubscriptionService,
66
$staticConfig: Config.IStaticConfig,
77
$commandsService: ICommandsService,
8-
$htmlHelpService: IHtmlHelpService,
8+
$helpService: IHelpService,
99
$options: ICommonOptions,
1010
$doctorService: IDoctorService,
1111
$analyticsService: IAnalyticsService,
1212
$logger: ILogger) {
13-
super($fs, $staticConfig, $commandsService, $htmlHelpService, $options, $doctorService, $analyticsService, $logger);
13+
super($fs, $staticConfig, $commandsService, $helpService, $options, $doctorService, $analyticsService, $logger);
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {

lib/config.ts

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ export class StaticConfig extends StaticConfigBase implements IStaticConfig {
6060

6161
public version = require("../package.json").version;
6262

63-
public get helpTextPath(): string {
64-
return path.join(__dirname, "../resources/help.txt");
65-
}
66-
6763
public get HTML_CLI_HELPERS_DIR(): string {
6864
return path.join(__dirname, "../docs/helpers");
6965
}

test/commands/post-install.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const createTestInjector = (): IInjector => {
1818
tryExecuteCommand: async (commandName: string, commandArguments: string[]): Promise<void> => undefined
1919
});
2020

21-
testInjector.register("htmlHelpService", {
21+
testInjector.register("helpService", {
2222
generateHtmlPages: async (): Promise<void> => undefined
2323
});
2424

test/platform-commands.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ErrorsNoFailStub implements IErrors {
5454
throw new Error();
5555
}
5656

57-
async beginCommand(action: () => Promise<boolean>, printHelpCommand: () => Promise<boolean>): Promise<boolean> {
57+
async beginCommand(action: () => Promise<boolean>, printHelpCommand: () => Promise<void>): Promise<boolean> {
5858
let result = false;
5959
try {
6060
result = await action();
@@ -148,6 +148,9 @@ function createTestInjector() {
148148
});
149149
testInjector.register("messages", Messages);
150150
testInjector.register("devicePathProvider", {});
151+
testInjector.register("helpService", {
152+
showCommandLineHelp: async (): Promise<void> => (undefined)
153+
});
151154

152155
return testInjector;
153156
}

test/platform-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ function createTestInjector() {
9191
});
9292
testInjector.register("messages", Messages);
9393
testInjector.register("devicePathProvider", {});
94+
testInjector.register("helpService", {
95+
showCommandLineHelp: async (): Promise<void> => (undefined)
96+
});
9497

9598
return testInjector;
9699
}

test/plugins-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ function createTestInjector() {
9898
});
9999
testInjector.register("xmlValidator", XmlValidator);
100100
testInjector.register("config", StaticConfigLib.Configuration);
101+
testInjector.register("helpService", {
102+
showCommandLineHelp: async (): Promise<void> => (undefined)
103+
});
101104

102105
return testInjector;
103106
}

test/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class ErrorsStub implements IErrors {
197197
throw new Error(message);
198198
}
199199

200-
async beginCommand(action: () => Promise<boolean>, printHelpCommand: () => Promise<boolean>): Promise<boolean> {
200+
async beginCommand(action: () => Promise<boolean>, printHelpCommand: () => Promise<void>): Promise<boolean> {
201201
throw new Error("not supported");
202202
}
203203

0 commit comments

Comments
 (0)