diff --git a/docs/design/analytics.md b/docs/design/analytics.md index a3a2785eeb..6ff986e389 100644 --- a/docs/design/analytics.md +++ b/docs/design/analytics.md @@ -111,7 +111,7 @@ See [the `debug` NPM library](https://www.npmjs.com/package/debug) for more info There are 2 ways of disabling usage analytics: -1. using `ng analytics off` (or changing the global configuration file yourself). This is the same +1. using `ng analytics off --global` (or changing the global configuration file yourself). This is the same as answering "No" to the prompt. 1. There is an `NG_CLI_ANALYTICS` environment variable that overrides the global configuration. That flag is a string that represents the User ID. If the string `"false"` is used it will diff --git a/packages/angular/cli/src/analytics/analytics.ts b/packages/angular/cli/src/analytics/analytics.ts index 34febb2a9d..95486cfb77 100644 --- a/packages/angular/cli/src/analytics/analytics.ts +++ b/packages/angular/cli/src/analytics/analytics.ts @@ -118,7 +118,7 @@ export async function promptGlobalAnalytics(force = false) { Thank you for sharing anonymous usage data. If you change your mind, the following command will disable this feature entirely: - ${colors.yellow('ng analytics off')} + ${colors.yellow('ng analytics off --global')} `); console.log(''); @@ -177,7 +177,7 @@ export async function promptProjectAnalytics(force = false): Promise { Thank you for sharing anonymous usage data. Should you change your mind, the following command will disable this feature entirely: - ${colors.yellow('ng analytics project off')} + ${colors.yellow('ng analytics off')} `); console.log(''); diff --git a/packages/angular/cli/src/commands/analytics/cli.ts b/packages/angular/cli/src/commands/analytics/cli.ts index 47d85a3604..e4916342cd 100644 --- a/packages/angular/cli/src/commands/analytics/cli.ts +++ b/packages/angular/cli/src/commands/analytics/cli.ts @@ -16,68 +16,50 @@ import { import { CommandModule, Options } from '../../command-builder/command-module'; interface AnalyticsCommandArgs { - 'setting-or-project': 'on' | 'off' | 'ci' | 'project' | 'prompt' | string; - 'project-setting'?: 'on' | 'off' | 'prompt' | string; + setting: 'on' | 'off' | 'prompt' | 'ci' | string; + global: boolean; } export class AnalyticsCommandModule extends CommandModule { - command = 'analytics '; + command = 'analytics '; describe = 'Configures the gathering of Angular CLI usage metrics.'; longDescriptionPath = join(__dirname, 'long-description.md'); builder(localYargs: Argv): Argv { return localYargs - .positional('setting-or-project', { - description: - 'Directly enables or disables all usage analytics for the user, or prompts the user to set the status interactively, ' + - 'or sets the default status for the project.', + .positional('setting', { + description: 'Directly enables or disables all usage analytics for the user.', choices: ['on', 'off', 'ci', 'prompt'], type: 'string', demandOption: true, }) - .positional('project-setting', { - description: 'Sets the default analytics enablement status for the project.', - choices: ['on', 'off', 'prompt'], - type: 'string', + .option('global', { + description: `Access the global configuration in the caller's home directory.`, + alias: ['g'], + type: 'boolean', + default: false, }) .strict(); } - async run({ - settingOrProject, - projectSetting, - }: Options): Promise { - if (settingOrProject === 'project' && projectSetting === undefined) { - throw new Error( - 'Argument "project" requires a second argument of one of the following value: on, off.', - ); - } - - switch (settingOrProject) { + async run({ setting, global }: Options): Promise { + const level = global ? 'global' : 'local'; + switch (setting) { case 'off': - setAnalyticsConfig('global', false); + setAnalyticsConfig(level, false); break; case 'on': - setAnalyticsConfig('global', true); + setAnalyticsConfig(level, true); break; case 'ci': - setAnalyticsConfig('global', 'ci'); - break; - case 'project': - switch (projectSetting) { - case 'off': - setAnalyticsConfig('local', false); - break; - case 'on': - setAnalyticsConfig('local', true); - break; - case 'prompt': - await promptProjectAnalytics(true); - break; - } + setAnalyticsConfig(level, 'ci'); break; case 'prompt': - await promptGlobalAnalytics(true); + if (global) { + await promptGlobalAnalytics(true); + } else { + await promptProjectAnalytics(true); + } break; } } diff --git a/packages/angular/cli/src/commands/analytics/long-description.md b/packages/angular/cli/src/commands/analytics/long-description.md index 6900aea53a..313edd4680 100644 --- a/packages/angular/cli/src/commands/analytics/long-description.md +++ b/packages/angular/cli/src/commands/analytics/long-description.md @@ -1,10 +1,9 @@ -The value of `setting-or-project` is one of the following. +The value of `setting` is one of the following. - `on`: Enables analytics gathering and reporting for the user. - `off`: Disables analytics gathering and reporting for the user. - `ci`: Enables analytics and configures reporting for use with Continuous Integration, which uses a common CI user. - `prompt`: Prompts the user to set the status interactively. -- `project`: Sets the default status for the project to the `project-setting` value, which can be any of the other values. The `project-setting` argument is ignored for all other values of `setting_or_project`. For further details, see [Gathering an Viewing CLI Usage Analytics](cli/usage-analytics-gathering). diff --git a/tests/legacy-cli/e2e/tests/commands/help/help-json.ts b/tests/legacy-cli/e2e/tests/commands/help/help-json.ts index 3c8786e06e..0b357179f4 100644 --- a/tests/legacy-cli/e2e/tests/commands/help/help-json.ts +++ b/tests/legacy-cli/e2e/tests/commands/help/help-json.ts @@ -4,30 +4,29 @@ export default async function () { // This test is use as a sanity check. const addHelpOutputSnapshot = JSON.stringify({ 'name': 'analytics', - 'command': 'ng analytics ', + 'command': 'ng analytics ', 'shortDescription': 'Configures the gathering of Angular CLI usage metrics.', 'longDescriptionRelativePath': '@angular/cli/src/commands/analytics/long-description.md', 'longDescription': - 'The value of `setting-or-project` is one of the following.\n\n- `on`: Enables analytics gathering and reporting for the user.\n- `off`: Disables analytics gathering and reporting for the user.\n- `ci`: Enables analytics and configures reporting for use with Continuous Integration,\n which uses a common CI user.\n- `prompt`: Prompts the user to set the status interactively.\n- `project`: Sets the default status for the project to the `project-setting` value, which can be any of the other values. The `project-setting` argument is ignored for all other values of `setting_or_project`.\n\nFor further details, see [Gathering an Viewing CLI Usage Analytics](cli/usage-analytics-gathering).\n', + 'The value of `setting` is one of the following.\n\n- `on`: Enables analytics gathering and reporting for the user.\n- `off`: Disables analytics gathering and reporting for the user.\n- `ci`: Enables analytics and configures reporting for use with Continuous Integration,\n which uses a common CI user.\n- `prompt`: Prompts the user to set the status interactively.\n\nFor further details, see [Gathering an Viewing CLI Usage Analytics](cli/usage-analytics-gathering).\n', 'options': [ + { + 'name': 'global', + 'type': 'boolean', + 'aliases': ['g'], + 'default': false, + 'description': "Access the global configuration in the caller's home directory.", + }, { 'name': 'help', 'type': 'boolean', 'description': 'Shows a help message for this command in the console.', }, { - 'name': 'project-setting', - 'type': 'string', - 'enum': ['on', 'off', 'prompt'], - 'description': 'Sets the default analytics enablement status for the project.', - 'positional': 1, - }, - { - 'name': 'setting-or-project', + 'name': 'setting', 'type': 'string', 'enum': ['on', 'off', 'ci', 'prompt'], - 'description': - 'Directly enables or disables all usage analytics for the user, or prompts the user to set the status interactively, or sets the default status for the project.', + 'description': 'Directly enables or disables all usage analytics for the user.', 'positional': 0, }, ],