error callback

This commit is contained in:
Timo Hocker 2020-05-28 09:20:53 +02:00
parent c0b1e51872
commit c18d216d2e
5 changed files with 14 additions and 3 deletions

View File

@ -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)

2
Jenkinsfile vendored
View File

@ -5,7 +5,7 @@ pipeline {
VERSION = VersionNumber([
versionNumberString:
'${BUILDS_ALL_TIME}',
versionPrefix: '1.7.',
versionPrefix: '1.8.',
worstResultForIncrement: 'SUCCESS'
])
}

View File

@ -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
},
]);

View File

@ -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 {

View File

@ -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);
}
}
}