UNPKG

3.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * @license
5 * Copyright Google Inc. All Rights Reserved.
6 *
7 * Use of this source code is governed by an MIT-style license that can be
8 * found in the LICENSE file at https://angular.io/license
9 */
10const analytics_1 = require("../models/analytics");
11const command_1 = require("../models/command");
12const analytics_2 = require("./analytics");
13class AnalyticsCommand extends command_1.Command {
14 async run(options) {
15 // Our parser does not support positional enums (won't report invalid parameters). Do the
16 // validation manually.
17 // TODO(hansl): fix parser to better support positionals. This would be a breaking change.
18 if (options.settingOrProject === undefined) {
19 if (options['--']) {
20 // The user passed positional arguments but they didn't validate.
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 // No argument were passed.
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}
79exports.AnalyticsCommand = AnalyticsCommand;