-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathanalytics.ts
71 lines (66 loc) · 2.48 KB
/
analytics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
export class AnalyticsCommandParameter implements ICommandParameter {
constructor(private $errors: IErrors) { }
mandatory = false;
async validate(validationValue: string): Promise<boolean> {
const val = validationValue || "";
switch (val.toLowerCase()) {
case "enable":
case "disable":
case "status":
case "":
return true;
default:
this.$errors.fail(`The value '${validationValue}' is not valid. Valid values are 'enable', 'disable' and 'status'.`);
}
}
}
class AnalyticsCommand implements ICommand {
constructor(protected $analyticsService: IAnalyticsService,
private $logger: ILogger,
private $errors: IErrors,
private $options: IOptions,
private settingName: string,
private humanReadableSettingName: string) { }
public allowedParameters = [new AnalyticsCommandParameter(this.$errors)];
public disableAnalytics = true;
public async execute(args: string[]): Promise<void> {
const arg = args[0] || "";
switch (arg.toLowerCase()) {
case "enable":
await this.$analyticsService.setStatus(this.settingName, true);
// TODO(Analytics): await this.$analyticsService.track(this.settingName, "enabled");
this.$logger.info(`${this.humanReadableSettingName} is now enabled.`);
break;
case "disable":
// TODO(Analytics): await this.$analyticsService.track(this.settingName, "disabled");
await this.$analyticsService.setStatus(this.settingName, false);
this.$logger.info(`${this.humanReadableSettingName} is now disabled.`);
break;
case "status":
case "":
this.$logger.info(await this.$analyticsService.getStatusMessage(this.settingName, this.$options.json, this.humanReadableSettingName));
break;
}
}
}
export class UsageReportingCommand extends AnalyticsCommand {
constructor(protected $analyticsService: IAnalyticsService,
$logger: ILogger,
$errors: IErrors,
$options: IOptions,
$staticConfig: Config.IStaticConfig) {
super($analyticsService, $logger, $errors, $options, $staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME, "Usage reporting");
}
}
$injector.registerCommand("usage-reporting", UsageReportingCommand);
export class ErrorReportingCommand extends AnalyticsCommand {
constructor(protected $analyticsService: IAnalyticsService,
$logger: ILogger,
$errors: IErrors,
$options: IOptions,
$staticConfig: Config.IStaticConfig
) {
super($analyticsService, $logger, $errors, $options, $staticConfig.ERROR_REPORT_SETTING_NAME, "Error reporting");
}
}
$injector.registerCommand("error-reporting", ErrorReportingCommand);