exit on interrupt
This commit is contained in:
@ -12,6 +12,13 @@ import { OptionProcess, Option } from '../Option';
|
||||
import { OptionSource } from './OptionSource';
|
||||
|
||||
export class InteractiveSource extends OptionSource {
|
||||
private _exit_on_interrupt: boolean;
|
||||
|
||||
public constructor (exit_on_interrupt: boolean) {
|
||||
super ();
|
||||
this._exit_on_interrupt = exit_on_interrupt;
|
||||
}
|
||||
|
||||
private get_message (opt: Option): string {
|
||||
return typeof opt.message === 'undefined'
|
||||
? `input ${opt.name}`
|
||||
@ -72,7 +79,12 @@ export class InteractiveSource extends OptionSource {
|
||||
for (const opt of options) {
|
||||
while (!opt.filled) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.prompt (opt);
|
||||
await this.prompt (opt)
|
||||
.catch ((e) => {
|
||||
if (this._exit_on_interrupt)
|
||||
process.exit (0);
|
||||
throw e;
|
||||
});
|
||||
if (!opt.filled)
|
||||
console.log ('input was invalid');
|
||||
}
|
||||
|
Reference in New Issue
Block a user