error callback
This commit is contained in:
		| @@ -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
									
									
								
							
							
						
						
									
										2
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							| @@ -5,7 +5,7 @@ pipeline { | ||||
|       VERSION = VersionNumber([ | ||||
|           versionNumberString: | ||||
|               '${BUILDS_ALL_TIME}', | ||||
|           versionPrefix: '1.7.', | ||||
|           versionPrefix: '1.8.', | ||||
|           worstResultForIncrement: 'SUCCESS' | ||||
|       ]) | ||||
|   } | ||||
|   | ||||
| @@ -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 | ||||
|   }, | ||||
| ]); | ||||
|  | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user