Skip to content

Commit 3d9f2a3

Browse files
committed
fix(@angular-devkit/schematics-cli): only show prompts in TTY terminals
1 parent 1ca167c commit 3d9f2a3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ export async function main({
270270
delete parsedArgs._;
271271

272272
// Add prompts.
273-
workflow.registry.usePromptProvider(_createPromptProvider());
274-
273+
if (argv['interactive'] && isTTY()) {
274+
workflow.registry.usePromptProvider(_createPromptProvider());
275+
}
275276

276277
/**
277278
* Execute the workflow, which will report the dry run events, run the tasks, and complete
@@ -337,6 +338,8 @@ function getUsage(): string {
337338
--list-schematics List all schematics from the collection, by name. A collection name
338339
should be suffixed by a colon. Example: '@schematics/schematics:'.
339340
341+
--no-interactive Disables interactive input prompts.
342+
340343
--verbose Show more information.
341344
342345
--help Show this message.
@@ -357,6 +360,7 @@ const booleanArgs = [
357360
'list-schematics',
358361
'listSchematics',
359362
'verbose',
363+
'interactive',
360364
];
361365

362366
function parseArgs(args: string[] | undefined): minimist.ParsedArgs {
@@ -368,13 +372,29 @@ function parseArgs(args: string[] | undefined): minimist.ParsedArgs {
368372
'allowPrivate': 'allow-private',
369373
},
370374
default: {
375+
'interactive': true,
371376
'debug': null,
372377
'dryRun': null,
373378
},
374379
'--': true,
375380
});
376381
}
377382

383+
function isTTY(): boolean {
384+
const isTruthy = (value: undefined | string) => {
385+
// Returns true if value is a string that is anything but 0 or false.
386+
return value !== undefined && value !== '0' && value.toUpperCase() !== 'FALSE';
387+
};
388+
389+
// If we force TTY, we always return true.
390+
const force = process.env['NG_FORCE_TTY'];
391+
if (force !== undefined) {
392+
return isTruthy(force);
393+
}
394+
395+
return !!process.stdout.isTTY && !isTruthy(process.env['CI']);
396+
}
397+
378398
if (require.main === module) {
379399
const args = process.argv.slice(2);
380400
main({ args })

0 commit comments

Comments
 (0)