[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.AnalyticsCommand = void 0;
|
---|
| 11 | const analytics_1 = require("../models/analytics");
|
---|
| 12 | const command_1 = require("../models/command");
|
---|
| 13 | const analytics_2 = require("./analytics");
|
---|
| 14 | class AnalyticsCommand extends command_1.Command {
|
---|
| 15 | async run(options) {
|
---|
| 16 | // Our parser does not support positional enums (won't report invalid parameters). Do the
|
---|
| 17 | // validation manually.
|
---|
| 18 | // TODO(hansl): fix parser to better support positionals. This would be a breaking change.
|
---|
| 19 | if (options.settingOrProject === undefined) {
|
---|
| 20 | if (options['--']) {
|
---|
| 21 | // The user passed positional arguments but they didn't validate.
|
---|
| 22 | this.logger.error(`Argument ${JSON.stringify(options['--'][0])} is invalid.`);
|
---|
| 23 | this.logger.error(`Please provide one of the following value: on, off, ci or project.`);
|
---|
| 24 | return 1;
|
---|
| 25 | }
|
---|
| 26 | else {
|
---|
| 27 | // No argument were passed.
|
---|
| 28 | await this.printHelp();
|
---|
| 29 | return 2;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | else if (options.settingOrProject == analytics_2.SettingOrProject.Project &&
|
---|
| 33 | options.projectSetting === undefined) {
|
---|
| 34 | this.logger.error(`Argument ${JSON.stringify(options.settingOrProject)} requires a second ` +
|
---|
| 35 | `argument of one of the following value: on, off.`);
|
---|
| 36 | return 2;
|
---|
| 37 | }
|
---|
| 38 | try {
|
---|
| 39 | switch (options.settingOrProject) {
|
---|
| 40 | case analytics_2.SettingOrProject.Off:
|
---|
| 41 | analytics_1.setAnalyticsConfig('global', false);
|
---|
| 42 | break;
|
---|
| 43 | case analytics_2.SettingOrProject.On:
|
---|
| 44 | analytics_1.setAnalyticsConfig('global', true);
|
---|
| 45 | break;
|
---|
| 46 | case analytics_2.SettingOrProject.Ci:
|
---|
| 47 | analytics_1.setAnalyticsConfig('global', 'ci');
|
---|
| 48 | break;
|
---|
| 49 | case analytics_2.SettingOrProject.Project:
|
---|
| 50 | switch (options.projectSetting) {
|
---|
| 51 | case analytics_2.ProjectSetting.Off:
|
---|
| 52 | analytics_1.setAnalyticsConfig('local', false);
|
---|
| 53 | break;
|
---|
| 54 | case analytics_2.ProjectSetting.On:
|
---|
| 55 | analytics_1.setAnalyticsConfig('local', true);
|
---|
| 56 | break;
|
---|
| 57 | case analytics_2.ProjectSetting.Prompt:
|
---|
| 58 | await analytics_1.promptProjectAnalytics(true);
|
---|
| 59 | break;
|
---|
| 60 | default:
|
---|
| 61 | await this.printHelp();
|
---|
| 62 | return 3;
|
---|
| 63 | }
|
---|
| 64 | break;
|
---|
| 65 | case analytics_2.SettingOrProject.Prompt:
|
---|
| 66 | await analytics_1.promptGlobalAnalytics(true);
|
---|
| 67 | break;
|
---|
| 68 | default:
|
---|
| 69 | await this.printHelp();
|
---|
| 70 | return 4;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | catch (err) {
|
---|
| 74 | this.logger.fatal(err.message);
|
---|
| 75 | return 1;
|
---|
| 76 | }
|
---|
| 77 | return 0;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | exports.AnalyticsCommand = AnalyticsCommand;
|
---|