mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 10:33:43 +08:00
feat(@angular/cli): add --global
option to ng analytics
command
With this change we add a `--global` option to `ng analytics` command. BREAKING CHANGE: Several changes to the `ng analytics` command syntax. - `ng analytics project <setting>` has been replaced with `ng analytics <setting>` - `ng analytics <setting>` has been replaced with `ng analytics <setting> --global`
This commit is contained in:
parent
b8564a638d
commit
afafa5788f
docs/design
packages/angular/cli/src
tests/legacy-cli/e2e/tests/commands/help
@ -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
|
||||
|
@ -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<boolean> {
|
||||
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('');
|
||||
|
||||
|
@ -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<AnalyticsCommandArgs> {
|
||||
command = 'analytics <setting-or-project>';
|
||||
command = 'analytics <setting>';
|
||||
describe = 'Configures the gathering of Angular CLI usage metrics.';
|
||||
longDescriptionPath = join(__dirname, 'long-description.md');
|
||||
|
||||
builder(localYargs: Argv): Argv<AnalyticsCommandArgs> {
|
||||
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<AnalyticsCommandArgs>): Promise<number | void> {
|
||||
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<AnalyticsCommandArgs>): Promise<void> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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).
|
||||
|
@ -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 <setting-or-project>',
|
||||
'command': 'ng analytics <setting>',
|
||||
'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,
|
||||
},
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user