/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { Argv } from 'yargs'; import { getAnalyticsInfoString, promptAnalytics, setAnalyticsConfig, } from '../../../analytics/analytics'; import { CommandModule, CommandModuleImplementation, Options, } from '../../../command-builder/command-module'; interface AnalyticsCommandArgs { global: boolean; } abstract class AnalyticsSettingModule extends CommandModule implements CommandModuleImplementation { builder(localYargs: Argv): Argv { return localYargs .option('global', { description: `Configure analytics gathering and reporting globally in the caller's home directory.`, alias: ['g'], type: 'boolean', default: false, }) .strict(); } abstract override run({ global }: Options): Promise; } export class AnalyticsDisableModule extends AnalyticsSettingModule implements CommandModuleImplementation { command = 'disable'; aliases = 'off'; describe = 'Disables analytics gathering and reporting for the user.'; async run({ global }: Options): Promise { await setAnalyticsConfig(global, false); process.stderr.write(await getAnalyticsInfoString(this.context)); } } export class AnalyticsEnableModule extends AnalyticsSettingModule implements CommandModuleImplementation { command = 'enable'; aliases = 'on'; describe = 'Enables analytics gathering and reporting for the user.'; async run({ global }: Options): Promise { await setAnalyticsConfig(global, true); process.stderr.write(await getAnalyticsInfoString(this.context)); } } export class AnalyticsPromptModule extends AnalyticsSettingModule implements CommandModuleImplementation { command = 'prompt'; describe = 'Prompts the user to set the analytics gathering status interactively.'; async run({ global }: Options): Promise { await promptAnalytics(this.context, global, true); } }