Skip to content

Commit afafa57

Browse files
alan-agius4clydin
authored andcommitted
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`
1 parent b8564a6 commit afafa57

File tree

5 files changed

+36
-56
lines changed

5 files changed

+36
-56
lines changed

‎docs/design/analytics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ See [the `debug` NPM library](https://www.npmjs.com/package/debug) for more info
111111

112112
There are 2 ways of disabling usage analytics:
113113

114-
1. using `ng analytics off` (or changing the global configuration file yourself). This is the same
114+
1. using `ng analytics off --global` (or changing the global configuration file yourself). This is the same
115115
as answering "No" to the prompt.
116116
1. There is an `NG_CLI_ANALYTICS` environment variable that overrides the global configuration.
117117
That flag is a string that represents the User ID. If the string `"false"` is used it will

‎packages/angular/cli/src/analytics/analytics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function promptGlobalAnalytics(force = false) {
118118
Thank you for sharing anonymous usage data. If you change your mind, the following
119119
command will disable this feature entirely:
120120
121-
${colors.yellow('ng analytics off')}
121+
${colors.yellow('ng analytics off --global')}
122122
`);
123123
console.log('');
124124

@@ -177,7 +177,7 @@ export async function promptProjectAnalytics(force = false): Promise<boolean> {
177177
Thank you for sharing anonymous usage data. Should you change your mind, the following
178178
command will disable this feature entirely:
179179
180-
${colors.yellow('ng analytics project off')}
180+
${colors.yellow('ng analytics off')}
181181
`);
182182
console.log('');
183183

‎packages/angular/cli/src/commands/analytics/cli.ts

+21-39
Original file line numberDiff line numberDiff line change
@@ -16,68 +16,50 @@ import {
1616
import { CommandModule, Options } from '../../command-builder/command-module';
1717

1818
interface AnalyticsCommandArgs {
19-
'setting-or-project': 'on' | 'off' | 'ci' | 'project' | 'prompt' | string;
20-
'project-setting'?: 'on' | 'off' | 'prompt' | string;
19+
setting: 'on' | 'off' | 'prompt' | 'ci' | string;
20+
global: boolean;
2121
}
2222

2323
export class AnalyticsCommandModule extends CommandModule<AnalyticsCommandArgs> {
24-
command = 'analytics <setting-or-project>';
24+
command = 'analytics <setting>';
2525
describe = 'Configures the gathering of Angular CLI usage metrics.';
2626
longDescriptionPath = join(__dirname, 'long-description.md');
2727

2828
builder(localYargs: Argv): Argv<AnalyticsCommandArgs> {
2929
return localYargs
30-
.positional('setting-or-project', {
31-
description:
32-
'Directly enables or disables all usage analytics for the user, or prompts the user to set the status interactively, ' +
33-
'or sets the default status for the project.',
30+
.positional('setting', {
31+
description: 'Directly enables or disables all usage analytics for the user.',
3432
choices: ['on', 'off', 'ci', 'prompt'],
3533
type: 'string',
3634
demandOption: true,
3735
})
38-
.positional('project-setting', {
39-
description: 'Sets the default analytics enablement status for the project.',
40-
choices: ['on', 'off', 'prompt'],
41-
type: 'string',
36+
.option('global', {
37+
description: `Access the global configuration in the caller's home directory.`,
38+
alias: ['g'],
39+
type: 'boolean',
40+
default: false,
4241
})
4342
.strict();
4443
}
4544

46-
async run({
47-
settingOrProject,
48-
projectSetting,
49-
}: Options<AnalyticsCommandArgs>): Promise<number | void> {
50-
if (settingOrProject === 'project' && projectSetting === undefined) {
51-
throw new Error(
52-
'Argument "project" requires a second argument of one of the following value: on, off.',
53-
);
54-
}
55-
56-
switch (settingOrProject) {
45+
async run({ setting, global }: Options<AnalyticsCommandArgs>): Promise<void> {
46+
const level = global ? 'global' : 'local';
47+
switch (setting) {
5748
case 'off':
58-
setAnalyticsConfig('global', false);
49+
setAnalyticsConfig(level, false);
5950
break;
6051
case 'on':
61-
setAnalyticsConfig('global', true);
52+
setAnalyticsConfig(level, true);
6253
break;
6354
case 'ci':
64-
setAnalyticsConfig('global', 'ci');
65-
break;
66-
case 'project':
67-
switch (projectSetting) {
68-
case 'off':
69-
setAnalyticsConfig('local', false);
70-
break;
71-
case 'on':
72-
setAnalyticsConfig('local', true);
73-
break;
74-
case 'prompt':
75-
await promptProjectAnalytics(true);
76-
break;
77-
}
55+
setAnalyticsConfig(level, 'ci');
7856
break;
7957
case 'prompt':
80-
await promptGlobalAnalytics(true);
58+
if (global) {
59+
await promptGlobalAnalytics(true);
60+
} else {
61+
await promptProjectAnalytics(true);
62+
}
8163
break;
8264
}
8365
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
The value of `setting-or-project` is one of the following.
1+
The value of `setting` is one of the following.
22

33
- `on`: Enables analytics gathering and reporting for the user.
44
- `off`: Disables analytics gathering and reporting for the user.
55
- `ci`: Enables analytics and configures reporting for use with Continuous Integration,
66
which uses a common CI user.
77
- `prompt`: Prompts the user to set the status interactively.
8-
- `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`.
98

109
For further details, see [Gathering an Viewing CLI Usage Analytics](cli/usage-analytics-gathering).

‎tests/legacy-cli/e2e/tests/commands/help/help-json.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@ export default async function () {
44
// This test is use as a sanity check.
55
const addHelpOutputSnapshot = JSON.stringify({
66
'name': 'analytics',
7-
'command': 'ng analytics <setting-or-project>',
7+
'command': 'ng analytics <setting>',
88
'shortDescription': 'Configures the gathering of Angular CLI usage metrics.',
99
'longDescriptionRelativePath': '@angular/cli/src/commands/analytics/long-description.md',
1010
'longDescription':
11-
'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',
11+
'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',
1212
'options': [
1313
{
14-
'name': 'help',
14+
'name': 'global',
1515
'type': 'boolean',
16-
'description': 'Shows a help message for this command in the console.',
16+
'aliases': ['g'],
17+
'default': false,
18+
'description': "Access the global configuration in the caller's home directory.",
1719
},
1820
{
19-
'name': 'project-setting',
20-
'type': 'string',
21-
'enum': ['on', 'off', 'prompt'],
22-
'description': 'Sets the default analytics enablement status for the project.',
23-
'positional': 1,
21+
'name': 'help',
22+
'type': 'boolean',
23+
'description': 'Shows a help message for this command in the console.',
2424
},
2525
{
26-
'name': 'setting-or-project',
26+
'name': 'setting',
2727
'type': 'string',
2828
'enum': ['on', 'off', 'ci', 'prompt'],
29-
'description':
30-
'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.',
29+
'description': 'Directly enables or disables all usage analytics for the user.',
3130
'positional': 0,
3231
},
3332
],

0 commit comments

Comments
 (0)