From 8eaa02d96f798aece2cdab003608dae3f4cd3b03 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 28 May 2020 18:54:34 +0200 Subject: [PATCH] fix --- AppTest.js | 6 +++++- lib/InteractiveOptions.ts | 8 ++++---- lib/Sources/ConfigSource.ts | 5 +++-- lib/Sources/InteractiveSource.ts | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/AppTest.js b/AppTest.js index 0c95cde..1acf357 100644 --- a/AppTest.js +++ b/AppTest.js @@ -19,7 +19,11 @@ const { InteractiveOptions } = require ('./dist/lib/index.js'); { name: 'num', type: 'number', env: 'TEST_NUM' }, { name: 'arr', type: 'array', env: 'TEST_ARR' }, { name: 'fld', type: 'folder', env: 'TEST_FOLDER' } - ], { exit_on_interrupt: true, configs: [ 'test.json' ] }); + ], { + exit_on_interrupt: true, + configs: [ 'test.json' ], + error_callback: console.log + }); await reader.parse (); console.log (reader.serialize (true)); }) (); diff --git a/lib/InteractiveOptions.ts b/lib/InteractiveOptions.ts index 76fb21e..1cca9a0 100644 --- a/lib/InteractiveOptions.ts +++ b/lib/InteractiveOptions.ts @@ -75,8 +75,8 @@ export class InteractiveOptions extends Persistent { && Array.isArray (source_config.configs) ) { this.sources.push (new ConfigSource ( - source_config.error_callback, - source_config.configs + source_config.configs, + source_config.error_callback )); } if (source_config.env !== false) @@ -85,8 +85,8 @@ export class InteractiveOptions extends Persistent { this.sources.push (new ArgSource (source_config.error_callback)); if (source_config.interactive !== false) { this.sources.push (new InteractiveSource ( - source_config.error_callback, - exit_on_interrupt + exit_on_interrupt, + source_config.error_callback )); } } diff --git a/lib/Sources/ConfigSource.ts b/lib/Sources/ConfigSource.ts index 697eb6c..ad80c28 100644 --- a/lib/Sources/ConfigSource.ts +++ b/lib/Sources/ConfigSource.ts @@ -17,7 +17,7 @@ import { OptionSource } from './OptionSource'; export class ConfigSource extends OptionSource { private _config_files: string[]; - public constructor (error_callback?:ErrorCallback, config_files: string[]) { + public constructor (config_files: string[], error_callback?:ErrorCallback) { super (error_callback); this._config_files = config_files; } @@ -55,7 +55,8 @@ export class ConfigSource extends OptionSource { data[key] = json[key]; } catch (e) { - this.error_callback ('*', `config file: ${f}`, e); + if (typeof this.error_callback !== 'undefined') + this.error_callback ('*', `config file: ${f}`, e); continue; } } diff --git a/lib/Sources/InteractiveSource.ts b/lib/Sources/InteractiveSource.ts index 1823562..2dddb79 100644 --- a/lib/Sources/InteractiveSource.ts +++ b/lib/Sources/InteractiveSource.ts @@ -9,14 +9,15 @@ /* eslint-disable no-process-exit */ import { Confirm, Input, List, AutoComplete } from 'enquirer'; import { OptionProcess, Option } from '../Option'; +import { ErrorCallback } from '../Types/ErrorCallback'; import { OptionSource } from './OptionSource'; export class InteractiveSource extends OptionSource { private _exit_on_interrupt: boolean; public constructor ( - error_callback?:ErrorCallback, - exit_on_interrupt: boolean + exit_on_interrupt: boolean, + error_callback?:ErrorCallback ) { super (error_callback); this._exit_on_interrupt = exit_on_interrupt;