error callback
This commit is contained in:
		@@ -1,5 +1,9 @@
 | 
				
			|||||||
# Changelog
 | 
					# Changelog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 1.8.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					callback in case an option could not be assigned instead of silently skipping
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 1.7.0
 | 
					## 1.7.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
parsing config files with [hjson](https://github.com/hjson/hjson-js)
 | 
					parsing config files with [hjson](https://github.com/hjson/hjson-js)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							@@ -5,7 +5,7 @@ pipeline {
 | 
				
			|||||||
      VERSION = VersionNumber([
 | 
					      VERSION = VersionNumber([
 | 
				
			||||||
          versionNumberString:
 | 
					          versionNumberString:
 | 
				
			||||||
              '${BUILDS_ALL_TIME}',
 | 
					              '${BUILDS_ALL_TIME}',
 | 
				
			||||||
          versionPrefix: '1.7.',
 | 
					          versionPrefix: '1.8.',
 | 
				
			||||||
          worstResultForIncrement: 'SUCCESS'
 | 
					          worstResultForIncrement: 'SUCCESS'
 | 
				
			||||||
      ])
 | 
					      ])
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
# @sapphirecode/console-app
 | 
					# @sapphirecode/console-app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
version: 1.7.x
 | 
					version: 1.8.x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
read parameters from env, console args or interactively
 | 
					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)
 | 
					    message: 'should foo be true?', // message when asking interactively (optional)
 | 
				
			||||||
    preset: [], // preset choices for string and path types (optional)
 | 
					    preset: [], // preset choices for string and path types (optional)
 | 
				
			||||||
    error: 'wrong input', // message to display when the user gives invalid input
 | 
					    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;
 | 
					  message?: string;
 | 
				
			||||||
  preset?: unknown[];
 | 
					  preset?: unknown[];
 | 
				
			||||||
  error?: string;
 | 
					  error?: string;
 | 
				
			||||||
 | 
					  error_callback?: (
 | 
				
			||||||
 | 
					    option: string,
 | 
				
			||||||
 | 
					    value: unknown,
 | 
				
			||||||
 | 
					    e: Error
 | 
				
			||||||
 | 
					  ) => unknown;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface OptionProcess extends Option {
 | 
					interface OptionProcess extends Option {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,8 @@ export abstract class OptionSource {
 | 
				
			|||||||
      opt.filled = true;
 | 
					      opt.filled = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (e) {
 | 
					    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