|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { join } from 'path'; |
10 | 9 | import { Argv } from 'yargs';
|
11 | 10 | import {
|
12 |
| - promptGlobalAnalytics, |
13 |
| - promptProjectAnalytics, |
14 |
| - setAnalyticsConfig, |
15 |
| -} from '../../analytics/analytics'; |
16 |
| -import { CommandModule, Options } from '../../command-builder/command-module'; |
| 11 | + CommandModule, |
| 12 | + CommandModuleImplementation, |
| 13 | + Options, |
| 14 | +} from '../../command-builder/command-module'; |
| 15 | +import { |
| 16 | + addCommandModuleToYargs, |
| 17 | + demandCommandFailureMessage, |
| 18 | +} from '../../command-builder/utilities/command'; |
| 19 | +import { AnalyticsInfoCommandModule } from './info/cli'; |
| 20 | +import { |
| 21 | + AnalyticsCIModule, |
| 22 | + AnalyticsOffModule, |
| 23 | + AnalyticsOnModule, |
| 24 | + AnalyticsPromptModule, |
| 25 | +} from './settings/cli'; |
17 | 26 |
|
18 |
| -interface AnalyticsCommandArgs { |
19 |
| - setting: 'on' | 'off' | 'prompt' | 'ci' | string; |
20 |
| - global: boolean; |
21 |
| -} |
| 27 | +export class AnalyticsCommandModule extends CommandModule implements CommandModuleImplementation { |
| 28 | + command = 'analytics'; |
| 29 | + describe = |
| 30 | + 'Configures the gathering of Angular CLI usage metrics. See https://angular.io/cli/usage-analytics-gathering'; |
| 31 | + longDescriptionPath?: string | undefined; |
22 | 32 |
|
23 |
| -export class AnalyticsCommandModule extends CommandModule<AnalyticsCommandArgs> { |
24 |
| - command = 'analytics <setting>'; |
25 |
| - describe = 'Configures the gathering of Angular CLI usage metrics.'; |
26 |
| - longDescriptionPath = join(__dirname, 'long-description.md'); |
| 33 | + builder(localYargs: Argv): Argv { |
| 34 | + const subcommands = [ |
| 35 | + AnalyticsCIModule, |
| 36 | + AnalyticsInfoCommandModule, |
| 37 | + AnalyticsOffModule, |
| 38 | + AnalyticsOnModule, |
| 39 | + AnalyticsPromptModule, |
| 40 | + ].sort(); |
27 | 41 |
|
28 |
| - builder(localYargs: Argv): Argv<AnalyticsCommandArgs> { |
29 |
| - return localYargs |
30 |
| - .positional('setting', { |
31 |
| - description: 'Directly enables or disables all usage analytics for the user.', |
32 |
| - choices: ['on', 'off', 'ci', 'prompt'], |
33 |
| - type: 'string', |
34 |
| - demandOption: true, |
35 |
| - }) |
36 |
| - .option('global', { |
37 |
| - description: `Access the global configuration in the caller's home directory.`, |
38 |
| - alias: ['g'], |
39 |
| - type: 'boolean', |
40 |
| - default: false, |
41 |
| - }) |
42 |
| - .strict(); |
43 |
| - } |
44 |
| - |
45 |
| - async run({ setting, global }: Options<AnalyticsCommandArgs>): Promise<void> { |
46 |
| - const level = global ? 'global' : 'local'; |
47 |
| - switch (setting) { |
48 |
| - case 'off': |
49 |
| - setAnalyticsConfig(level, false); |
50 |
| - break; |
51 |
| - case 'on': |
52 |
| - setAnalyticsConfig(level, true); |
53 |
| - break; |
54 |
| - case 'ci': |
55 |
| - setAnalyticsConfig(level, 'ci'); |
56 |
| - break; |
57 |
| - case 'prompt': |
58 |
| - if (global) { |
59 |
| - await promptGlobalAnalytics(true); |
60 |
| - } else { |
61 |
| - await promptProjectAnalytics(true); |
62 |
| - } |
63 |
| - break; |
| 42 | + for (const module of subcommands) { |
| 43 | + localYargs = addCommandModuleToYargs(localYargs, module, this.context); |
64 | 44 | }
|
| 45 | + |
| 46 | + return localYargs.demandCommand(1, demandCommandFailureMessage).strict(); |
65 | 47 | }
|
| 48 | + |
| 49 | + run(_options: Options<{}>): void {} |
66 | 50 | }
|
0 commit comments