| 
									
										
										
										
											2020-06-14 03:10:19 +03:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var colors = require('colors') | 
					
						
							|  |  |  | var object = require('ig-object') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var argv = require('./argv') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | var p =  | 
					
						
							|  |  |  | module.p = | 
					
						
							|  |  |  | argv.Parser({ | 
					
						
							| 
									
										
										
										
											2020-06-25 18:31:06 +03:00
										 |  |  | 		// disable exit on error...
 | 
					
						
							|  |  |  | 		handleErrorExit: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 		'@help': '-help', | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 		'-verbose': function(){ | 
					
						
							|  |  |  | 			console.log('>>> VERBOSE:', ...arguments) | 
					
						
							|  |  |  | 			return 'verbose' | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 		'-c': '@command', | 
					
						
							|  |  |  | 		'@cmd': '@command', | 
					
						
							|  |  |  | 		'@command': { | 
					
						
							|  |  |  | 			priority: -50, | 
					
						
							|  |  |  | 			handler: function(){ | 
					
						
							|  |  |  | 				console.log('>>> COMMAND:', ...arguments) | 
					
						
							|  |  |  | 				return 'command' | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 03:53:32 +03:00
										 |  |  | 		'-r': '-required', | 
					
						
							|  |  |  | 		'-required': { | 
					
						
							|  |  |  | 			doc: 'Required option', | 
					
						
							|  |  |  | 			required: true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 00:28:28 +03:00
										 |  |  | 		'-value': { | 
					
						
							|  |  |  | 			doc: 'Value option', | 
					
						
							|  |  |  | 			arg: 'VALUE | valueValue', | 
					
						
							|  |  |  | 			default: 333, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 20:31:20 +03:00
										 |  |  | 		// XXX need to handle value correctly...
 | 
					
						
							| 
									
										
										
										
											2020-06-29 16:24:40 +03:00
										 |  |  | 		'-test': argv.Parser({ | 
					
						
							|  |  |  | 			env: 'TEST', | 
					
						
							| 
									
										
										
										
											2020-07-03 03:53:32 +03:00
										 |  |  | 			arg: 'TEST', | 
					
						
							| 
									
										
										
										
											2020-07-02 02:17:28 +03:00
										 |  |  | 			default: 'moo', | 
					
						
							| 
									
										
										
										
											2020-06-29 16:24:40 +03:00
										 |  |  | 		}).then(function(){ | 
					
						
							|  |  |  | 			console.log('TEST', ...arguments) }), | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 20:31:20 +03:00
										 |  |  | 		'-int': { | 
					
						
							|  |  |  | 			arg: 'INT|int', | 
					
						
							|  |  |  | 			type: 'int', | 
					
						
							|  |  |  | 			valueRequired: true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 		'@nested': argv.Parser({ | 
					
						
							|  |  |  | 			doc: 'nested parser.', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			'@nested': argv.Parser({ | 
					
						
							|  |  |  | 				doc: 'nested nested parser.', | 
					
						
							| 
									
										
										
										
											2020-06-29 14:05:55 +03:00
										 |  |  | 			}).then(function(){ | 
					
						
							|  |  |  | 				console.log('NESTED NESTED DONE', ...arguments)}), | 
					
						
							|  |  |  | 		}).then(function(){ | 
					
						
							|  |  |  | 			console.log('NESTED DONE', ...arguments) }), | 
					
						
							| 
									
										
										
										
											2020-06-28 02:13:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 20:31:20 +03:00
										 |  |  | 		'-\\*': { | 
					
						
							|  |  |  | 			handler: function(){ | 
					
						
							|  |  |  | 				console.log('-\\*:', ...arguments) } }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 22:04:47 +03:00
										 |  |  | 		//'@*': undefined,
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-28 02:13:43 +03:00
										 |  |  | 		// these aliases will not get shown...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// dead-end alias...
 | 
					
						
							|  |  |  | 		'-d': '-dead-end', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// alias loops...
 | 
					
						
							|  |  |  | 		'-z': '-z', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		'-x': '-y', | 
					
						
							|  |  |  | 		'-y': '-x', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		'-a': '-b', | 
					
						
							|  |  |  | 		'-b': '-c', | 
					
						
							|  |  |  | 		'-c': '-a', | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	.then(function(){ | 
					
						
							| 
									
										
										
										
											2020-06-29 02:51:06 +03:00
										 |  |  | 		console.log('DONE', ...arguments) }) | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 	.stop(function(){ | 
					
						
							| 
									
										
										
										
											2020-07-01 17:28:10 +03:00
										 |  |  | 		console.log('STOP', ...arguments) }) | 
					
						
							| 
									
										
										
										
											2020-06-16 18:31:58 +03:00
										 |  |  | 	.error(function(){ | 
					
						
							| 
									
										
										
										
											2020-07-01 17:28:10 +03:00
										 |  |  | 		console.log('ERROR', ...arguments) }) | 
					
						
							| 
									
										
										
										
											2020-06-15 17:17:04 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2020-06-15 17:17:04 +03:00
										 |  |  | console.log('  ->', p(['test', '--verbose', 'a', 'b', 'c'])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log('  ->', p(['test', '-c', 'a', 'b', 'c'])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log('  ->', p(['test', 'command', 'a', 'b', 'c'])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log('---') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | p(['test', 'nested', '-h']) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 17:17:04 +03:00
										 |  |  | p(['test', '-h']) | 
					
						
							| 
									
										
										
										
											2020-06-16 15:48:43 +03:00
										 |  |  | //*/
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-02 03:18:27 +03:00
										 |  |  | typeof(__filename) != 'undefined' | 
					
						
							|  |  |  | 	&& __filename == (require.main || {}).filename | 
					
						
							| 
									
										
										
										
											2020-07-04 18:29:25 +03:00
										 |  |  | 	&& console.log(p()) | 
					
						
							| 
									
										
										
										
											2020-06-14 03:10:19 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |