dialog fix

This commit is contained in:
Timo Hocker 2020-04-16 08:00:53 +02:00
parent 05d4839dea
commit 6a525d8120
2 changed files with 26 additions and 10 deletions

5
lib/dialog.ts Normal file
View File

@ -0,0 +1,5 @@
class DialogHandler {
public static catch (): void {
process.exit ();
}
}

View File

@ -33,7 +33,7 @@ export default class Copyright implements Snippet {
if (await new Confirm({
message: 'should those settings be saved for the next run?'
}).run()) {
}).run().catch(DialogHandler.catch)) {
this.save_options_file();
}
}
@ -41,18 +41,18 @@ export default class Copyright implements Snippet {
private async gather_options (): Promise<void> {
this.options = (new CopyrightOptions);
this.options.author = await new Input ({ message: 'author' })
.run ();
.run ().catch(DialogHandler.catch);
this.options.email = await new Input ({ message: 'email' })
.run ();
.run ().catch(DialogHandler.catch);
this.options.company = await new Input ({ message: 'company' })
.run ();
.run ().catch(DialogHandler.catch);
this.options.software = await new Input ({ message: 'software name' })
.run ();
.run ().catch(DialogHandler.catch);
this.options.has_license = await new Confirm ({
message:
'would you like to specify a license?'
})
.run ();
.run ().catch(DialogHandler.catch);
if (this.options.has_license) {
this.options.license = await new AutoComplete ({
name: 'license',
@ -60,20 +60,31 @@ export default class Copyright implements Snippet {
limit: 10,
choices: findLicense ('')
})
.run ();
.run ().catch(DialogHandler.catch);
}
}
private async load_options_file (): Promise<void> {
const file_path = path.join (this.cwd, '.liconfig.json');
this.options = null;
if (await fs.pathExists (file_path)) {
this.options = JSON.parse (
const options = JSON.parse (
await fs.readFile (file_path, 'utf-8')
);
}
this.options = null;
// eslint-disable-next-line no-console
console.log(`author: ${options.author}
email: ${options.email}
company: ${options.company}
software name: ${options.software}
license: ${options.license}`);
const should_load = await new Confirm({
message: 'should those options be used?'
}).run().catch(DialogHandler.catch);
if (should_load)
this.options = options;
}
}
private async save_options_file(): Promise<void> {