Skip to content

Commit 3a23130

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/cli): don't display options multiple times in schematics help output
Previously, we disabled options in the help output multiple times. Previous output ``` Generates and/or modifies files based on a schematic. usage: ng generate c <name> [options] arguments: schematic The schematic or collection:schematic to generate. name The name of the component. options: --change-detection (-c) The change detection strategy to use in the new component. --defaults When true, disables interactive input prompts for options with a default. --display-block (-b) Specifies if the style will contain `:host { display: block; }`. --dry-run (-d) When true, runs through and reports activity without writing out results. --entry-component When true, the new component is the entry component of the declaring NgModule. --export When true, the declaring NgModule exports this component. --flat When true, creates the new files at the top level of the current project. --force (-f) When true, forces overwriting of existing files. --help Shows a help message for this command in the console. --inline-style (-s) When true, includes styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. --inline-template (-t) When true, includes template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. --interactive When false, disables interactive input prompts. --lint-fix When true, applies lint fixes after generating the component. --module (-m) The declaring NgModule. --prefix (-p) The prefix to apply to the generated component selector. --project The name of the project. --selector The HTML selector to use for this component. --skip-import When true, does not import this component into the owning NgModule. --skip-selector Specifies if the component should have a selector or not. --skip-tests When true, does not create "spec.ts" test files for the new component. --style The file extension or preprocessor to use for style files. --type Adds a developer-defined type to the filename, in the format "name.type.ts". --view-encapsulation (-v) The view encapsulation strategy to use in the new component. Help for schematic c Creates a new generic component definition in the given or default project. arguments: name The name of the component. options: --change-detection (-c) The change detection strategy to use in the new component. --display-block (-b) Specifies if the style will contain `:host { display: block; }`. --entry-component When true, the new component is the entry component of the declaring NgModule. --export When true, the declaring NgModule exports this component. --flat When true, creates the new files at the top level of the current project. --inline-style (-s) When true, includes styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. --inline-template (-t) When true, includes template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. --lint-fix When true, applies lint fixes after generating the component. --module (-m) The declaring NgModule. --prefix (-p) The prefix to apply to the generated component selector. --project The name of the project. --selector The HTML selector to use for this component. --skip-import When true, does not import this component into the owning NgModule. --skip-selector Specifies if the component should have a selector or not. --skip-tests When true, does not create "spec.ts" test files for the new component. --style The file extension or preprocessor to use for style files. --type Adds a developer-defined type to the filename, in the format "name.type.ts". --view-encapsulation (-v) The view encapsulation strategy to use in the new component. To see help for a schematic run: ng generate <schematic> --help ``` New output ``` Generates and/or modifies files based on a schematic. usage: ng generate c <name> [options] arguments: schematic The schematic or collection:schematic to generate. name The name of the component. options: --change-detection (-c) The change detection strategy to use in the new component. --defaults Disable interactive input prompts for options with a default. --display-block (-b) Specifies if the style will contain `:host { display: block; }`. --dry-run (-d) Run through and reports activity without writing out results. --export The declaring NgModule exports this component. --flat Create the new files at the top level of the current project. --force (-f) Force overwriting of existing files. --help Shows a help message for this command in the console. --inline-style (-s) Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. --inline-template (-t) Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. --interactive Enable interactive input prompts. --lint-fix Apply lint fixes after generating the component. --module (-m) The declaring NgModule. --prefix (-p) The prefix to apply to the generated component selector. --project The name of the project. --selector The HTML selector to use for this component. --skip-import Do not import this component into the owning NgModule. --skip-selector Specifies if the component should have a selector or not. --skip-tests Do not create "spec.ts" test files for the new component. --style The file extension or preprocessor to use for style files. --type Adds a developer-defined type to the filename, in the format "name.type.ts". --view-encapsulation (-v) The view encapsulation strategy to use in the new component. To see help for a schematic run: ng generate <schematic> --help ``` (cherry picked from commit f6135a2)
1 parent 1b9676f commit 3a23130

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

packages/angular/cli/models/command.ts

-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
7575
this.logger.info('');
7676
}
7777

78-
protected async printHelpSubcommand(subcommand: SubCommandDescription) {
79-
this.logger.info(subcommand.description);
80-
81-
await this.printHelpOptions(subcommand.options);
82-
}
83-
8478
protected async printHelpOptions(options: Option[] = this.description.options) {
8579
const args = options.filter((opt) => opt.positional !== undefined);
8680
const opts = options.filter((opt) => opt.positional === undefined);

packages/angular/cli/models/schematic-command.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export abstract class SchematicCommand<
8282
schematic.description.schemaJson || {},
8383
);
8484

85+
this.description.description = schematic.description.description;
8586
this.description.options.push(...options.filter((x) => !x.hidden));
8687

8788
// Remove any user analytics from schematics that are NOT part of our safelist.
@@ -132,9 +133,6 @@ export abstract class SchematicCommand<
132133
this.logger.info(` ${schematicName}`);
133134
});
134135
});
135-
} else if (schematicNames.length == 1) {
136-
this.logger.info('Help for schematic ' + schematicNames[0]);
137-
await this.printHelpSubcommand(subCommandOption.subcommands[schematicNames[0]]);
138136
}
139137

140138
return 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ng } from '../../utils/process';
2+
3+
export default async function() {
4+
// Verify that there are no duplicate options
5+
const { stdout } = await ng('generate', 'component', '--help');
6+
const firstIndex = stdout.indexOf('--prefix');
7+
8+
if (firstIndex < 0) {
9+
console.log(stdout);
10+
throw new Error('--prefix was not part of the help output.');
11+
}
12+
13+
if (firstIndex !== stdout.lastIndexOf('--prefix')) {
14+
console.log(stdout);
15+
throw new Error('--prefix first and last index were different. Possible duplicate output!');
16+
}
17+
}

0 commit comments

Comments
 (0)