diff --git a/lib/dialog.ts b/lib/dialog.ts new file mode 100644 index 0000000..00dacfd --- /dev/null +++ b/lib/dialog.ts @@ -0,0 +1,5 @@ +class DialogHandler { + public static catch (): void { + process.exit (); + } +} diff --git a/lib/snippets/copyright/index.ts b/lib/snippets/copyright/index.ts index d41a92d..5312d05 100644 --- a/lib/snippets/copyright/index.ts +++ b/lib/snippets/copyright/index.ts @@ -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 { 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 { 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') ); + + // 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; } - - this.options = null; } private async save_options_file(): Promise {