mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 19:13:34 +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
@ -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:
|
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.
|
as answering "No" to the prompt.
|
||||||
1. There is an `NG_CLI_ANALYTICS` environment variable that overrides the global configuration.
|
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
|
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
|
Thank you for sharing anonymous usage data. If you change your mind, the following
|
||||||
command will disable this feature entirely:
|
command will disable this feature entirely:
|
||||||
|
|
||||||
${colors.yellow('ng analytics off')}
|
${colors.yellow('ng analytics off --global')}
|
||||||
`);
|
`);
|
||||||
console.log('');
|
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
|
Thank you for sharing anonymous usage data. Should you change your mind, the following
|
||||||
command will disable this feature entirely:
|
command will disable this feature entirely:
|
||||||
|
|
||||||
${colors.yellow('ng analytics project off')}
|
${colors.yellow('ng analytics off')}
|
||||||
`);
|
`);
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
|
@ -16,68 +16,50 @@ import {
|
|||||||
import { CommandModule, Options } from '../../command-builder/command-module';
|
import { CommandModule, Options } from '../../command-builder/command-module';
|
||||||
|
|
||||||
interface AnalyticsCommandArgs {
|
interface AnalyticsCommandArgs {
|
||||||
'setting-or-project': 'on' | 'off' | 'ci' | 'project' | 'prompt' | string;
|
setting: 'on' | 'off' | 'prompt' | 'ci' | string;
|
||||||
'project-setting'?: 'on' | 'off' | 'prompt' | string;
|
global: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AnalyticsCommandModule extends CommandModule<AnalyticsCommandArgs> {
|
export class AnalyticsCommandModule extends CommandModule<AnalyticsCommandArgs> {
|
||||||
command = 'analytics <setting-or-project>';
|
command = 'analytics <setting>';
|
||||||
describe = 'Configures the gathering of Angular CLI usage metrics.';
|
describe = 'Configures the gathering of Angular CLI usage metrics.';
|
||||||
longDescriptionPath = join(__dirname, 'long-description.md');
|
longDescriptionPath = join(__dirname, 'long-description.md');
|
||||||
|
|
||||||
builder(localYargs: Argv): Argv<AnalyticsCommandArgs> {
|
builder(localYargs: Argv): Argv<AnalyticsCommandArgs> {
|
||||||
return localYargs
|
return localYargs
|
||||||
.positional('setting-or-project', {
|
.positional('setting', {
|
||||||
description:
|
description: 'Directly enables or disables all usage analytics for the user.',
|
||||||
'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.',
|
|
||||||
choices: ['on', 'off', 'ci', 'prompt'],
|
choices: ['on', 'off', 'ci', 'prompt'],
|
||||||
type: 'string',
|
type: 'string',
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
})
|
})
|
||||||
.positional('project-setting', {
|
.option('global', {
|
||||||
description: 'Sets the default analytics enablement status for the project.',
|
description: `Access the global configuration in the caller's home directory.`,
|
||||||
choices: ['on', 'off', 'prompt'],
|
alias: ['g'],
|
||||||
type: 'string',
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
}
|
}
|
||||||
|
|
||||||
async run({
|
async run({ setting, global }: Options<AnalyticsCommandArgs>): Promise<void> {
|
||||||
settingOrProject,
|
const level = global ? 'global' : 'local';
|
||||||
projectSetting,
|
switch (setting) {
|
||||||
}: 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) {
|
|
||||||
case 'off':
|
case 'off':
|
||||||
setAnalyticsConfig('global', false);
|
setAnalyticsConfig(level, false);
|
||||||
break;
|
break;
|
||||||
case 'on':
|
case 'on':
|
||||||
setAnalyticsConfig('global', true);
|
setAnalyticsConfig(level, true);
|
||||||
break;
|
break;
|
||||||
case 'ci':
|
case 'ci':
|
||||||
setAnalyticsConfig('global', 'ci');
|
setAnalyticsConfig(level, 'ci');
|
||||||
break;
|
|
||||||
case 'project':
|
|
||||||
switch (projectSetting) {
|
|
||||||
case 'off':
|
|
||||||
setAnalyticsConfig('local', false);
|
|
||||||
break;
|
|
||||||
case 'on':
|
|
||||||
setAnalyticsConfig('local', true);
|
|
||||||
break;
|
|
||||||
case 'prompt':
|
|
||||||
await promptProjectAnalytics(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'prompt':
|
case 'prompt':
|
||||||
|
if (global) {
|
||||||
await promptGlobalAnalytics(true);
|
await promptGlobalAnalytics(true);
|
||||||
|
} else {
|
||||||
|
await promptProjectAnalytics(true);
|
||||||
|
}
|
||||||
break;
|
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.
|
- `on`: Enables analytics gathering and reporting for the user.
|
||||||
- `off`: Disables 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,
|
- `ci`: Enables analytics and configures reporting for use with Continuous Integration,
|
||||||
which uses a common CI user.
|
which uses a common CI user.
|
||||||
- `prompt`: Prompts the user to set the status interactively.
|
- `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).
|
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.
|
// This test is use as a sanity check.
|
||||||
const addHelpOutputSnapshot = JSON.stringify({
|
const addHelpOutputSnapshot = JSON.stringify({
|
||||||
'name': 'analytics',
|
'name': 'analytics',
|
||||||
'command': 'ng analytics <setting-or-project>',
|
'command': 'ng analytics <setting>',
|
||||||
'shortDescription': 'Configures the gathering of Angular CLI usage metrics.',
|
'shortDescription': 'Configures the gathering of Angular CLI usage metrics.',
|
||||||
'longDescriptionRelativePath': '@angular/cli/src/commands/analytics/long-description.md',
|
'longDescriptionRelativePath': '@angular/cli/src/commands/analytics/long-description.md',
|
||||||
'longDescription':
|
'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': [
|
'options': [
|
||||||
|
{
|
||||||
|
'name': 'global',
|
||||||
|
'type': 'boolean',
|
||||||
|
'aliases': ['g'],
|
||||||
|
'default': false,
|
||||||
|
'description': "Access the global configuration in the caller's home directory.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'help',
|
'name': 'help',
|
||||||
'type': 'boolean',
|
'type': 'boolean',
|
||||||
'description': 'Shows a help message for this command in the console.',
|
'description': 'Shows a help message for this command in the console.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'project-setting',
|
'name': 'setting',
|
||||||
'type': 'string',
|
|
||||||
'enum': ['on', 'off', 'prompt'],
|
|
||||||
'description': 'Sets the default analytics enablement status for the project.',
|
|
||||||
'positional': 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'setting-or-project',
|
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'enum': ['on', 'off', 'ci', 'prompt'],
|
'enum': ['on', 'off', 'ci', 'prompt'],
|
||||||
'description':
|
'description': 'Directly enables or disables all usage analytics for the user.',
|
||||||
'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': 0,
|
'positional': 0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user