Skip to content

Commit fd289a9

Browse files
committed
feat(@angular/cli): add --defaults option to ng new
Any option with a default value will not be prompted (if a prompt is defined) and the default will be used instead. Closes angular#12084
1 parent 39b4cc0 commit fd289a9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

packages/angular/cli/commands/new-impl.ts

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class NewCommand extends SchematicCommand {
5858
dryRun: options.dryRun,
5959
force: options.force,
6060
interactive: options.interactive,
61+
defaults: options.defaults,
6162
});
6263
}
6364

@@ -72,6 +73,7 @@ export class NewCommand extends SchematicCommand {
7273
delete opts.verbose;
7374
delete opts.collection;
7475
delete opts.interactive;
76+
delete opts.defaults;
7577

7678
return opts;
7779
}

packages/angular/cli/commands/new.json

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
"type": "boolean",
3939
"default": "true",
4040
"description": "Disables interactive inputs (i.e., prompts)."
41+
},
42+
"defaults": {
43+
"type": "boolean",
44+
"default": "false",
45+
"description": "Disables interactive inputs (i.e., prompts) for options with a default."
4146
}
4247
},
4348
"required": []

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

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface RunSchematicOptions {
6262
force: boolean;
6363
showNothingDone?: boolean;
6464
interactive?: boolean;
65+
defaults?: boolean;
6566
}
6667

6768
export interface GetOptionsOptions {
@@ -282,6 +283,11 @@ export abstract class SchematicCommand extends Command {
282283
});
283284

284285
if (options.interactive !== false && process.stdout.isTTY) {
286+
if (options.defaults) {
287+
(workflow.registry as schema.CoreSchemaRegistry)
288+
.addPreTransform(schema.transforms.addUndefinedDefaults);
289+
}
290+
285291
workflow.registry.usePromptProvider((definitions: Array<schema.PromptDefinition>) => {
286292
const questions: inquirer.Questions = definitions.map(definition => {
287293
const question: inquirer.Question = {

0 commit comments

Comments
 (0)