From c18d216d2ebfcca0abf20e42f735085401ab8936 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 28 May 2020 09:20:53 +0200 Subject: [PATCH] error callback --- CHANGELOG.md | 4 ++++ Jenkinsfile | 2 +- README.md | 3 ++- lib/Option.ts | 5 +++++ lib/Sources/OptionSource.ts | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 314b7e3..b4a66f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.8.0 + +callback in case an option could not be assigned instead of silently skipping + ## 1.7.0 parsing config files with [hjson](https://github.com/hjson/hjson-js) diff --git a/Jenkinsfile b/Jenkinsfile index 5640634..b3515ba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { VERSION = VersionNumber([ versionNumberString: '${BUILDS_ALL_TIME}', - versionPrefix: '1.7.', + versionPrefix: '1.8.', worstResultForIncrement: 'SUCCESS' ]) } diff --git a/README.md b/README.md index e72115f..1ccbd64 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @sapphirecode/console-app -version: 1.7.x +version: 1.8.x read parameters from env, console args or interactively @@ -31,6 +31,7 @@ const reader = new InteractiveOptions([ message: 'should foo be true?', // message when asking interactively (optional) preset: [], // preset choices for string and path types (optional) error: 'wrong input', // message to display when the user gives invalid input + error_callback: (opt, val, err)=>{...} // function to call when an option value could not be read }, ]); diff --git a/lib/Option.ts b/lib/Option.ts index 2d5a77e..621fe8b 100644 --- a/lib/Option.ts +++ b/lib/Option.ts @@ -19,6 +19,11 @@ interface Option { message?: string; preset?: unknown[]; error?: string; + error_callback?: ( + option: string, + value: unknown, + e: Error + ) => unknown; } interface OptionProcess extends Option { diff --git a/lib/Sources/OptionSource.ts b/lib/Sources/OptionSource.ts index 95bb90f..2214329 100644 --- a/lib/Sources/OptionSource.ts +++ b/lib/Sources/OptionSource.ts @@ -19,7 +19,8 @@ export abstract class OptionSource { opt.filled = true; } catch (e) { - // could not assign + if (typeof opt.error_callback !== 'undefined') + opt.error_callback (opt.name, value, e); } } }