1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const analytics_1 = require("../models/analytics");
|
11 | const command_1 = require("../models/command");
|
12 | const analytics_2 = require("./analytics");
|
13 | class AnalyticsCommand extends command_1.Command {
|
14 | async run(options) {
|
15 |
|
16 |
|
17 |
|
18 | if (options.settingOrProject === undefined) {
|
19 | if (options['--']) {
|
20 |
|
21 | this.logger.error(`Argument ${JSON.stringify(options['--'][0])} is invalid.`);
|
22 | this.logger.error(`Please provide one of the following value: on, off, ci or project.`);
|
23 | return 1;
|
24 | }
|
25 | else {
|
26 |
|
27 | await this.printHelp(options);
|
28 | return 2;
|
29 | }
|
30 | }
|
31 | else if (options.settingOrProject == analytics_2.SettingOrProject.Project
|
32 | && options.projectSetting === undefined) {
|
33 | this.logger.error(`Argument ${JSON.stringify(options.settingOrProject)} requires a second `
|
34 | + `argument of one of the following value: on, off.`);
|
35 | return 2;
|
36 | }
|
37 | try {
|
38 | switch (options.settingOrProject) {
|
39 | case analytics_2.SettingOrProject.Off:
|
40 | analytics_1.setAnalyticsConfig('global', false);
|
41 | break;
|
42 | case analytics_2.SettingOrProject.On:
|
43 | analytics_1.setAnalyticsConfig('global', true);
|
44 | break;
|
45 | case analytics_2.SettingOrProject.Ci:
|
46 | analytics_1.setAnalyticsConfig('global', 'ci');
|
47 | break;
|
48 | case analytics_2.SettingOrProject.Project:
|
49 | switch (options.projectSetting) {
|
50 | case analytics_2.ProjectSetting.Off:
|
51 | analytics_1.setAnalyticsConfig('local', false);
|
52 | break;
|
53 | case analytics_2.ProjectSetting.On:
|
54 | analytics_1.setAnalyticsConfig('local', true);
|
55 | break;
|
56 | case analytics_2.ProjectSetting.Prompt:
|
57 | await analytics_1.promptProjectAnalytics(true);
|
58 | break;
|
59 | default:
|
60 | await this.printHelp(options);
|
61 | return 3;
|
62 | }
|
63 | break;
|
64 | case analytics_2.SettingOrProject.Prompt:
|
65 | await analytics_1.promptGlobalAnalytics(true);
|
66 | break;
|
67 | default:
|
68 | await this.printHelp(options);
|
69 | return 4;
|
70 | }
|
71 | }
|
72 | catch (err) {
|
73 | this.logger.fatal(err.message);
|
74 | return 1;
|
75 | }
|
76 | return 0;
|
77 | }
|
78 | }
|
79 | exports.AnalyticsCommand = AnalyticsCommand;
|