mirror of
				https://github.com/flynx/argv.js.git
				synced 2025-10-31 03:30:08 +00:00 
			
		
		
		
	docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									5ca866263a
								
							
						
					
					
						commit
						1d917ba679
					
				
							
								
								
									
										30
									
								
								argv.js
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								argv.js
									
									
									
									
									
								
							| @ -100,19 +100,22 @@ var afterCallbackCall = function(name, context, ...args){ | |||||||
| // XXX should .options(..), .commands(..) and .handler(..) be:
 | // XXX should .options(..), .commands(..) and .handler(..) be:
 | ||||||
| // 		.getOptions(..), .getCommands(..) and .getHandler(..) respectively???
 | // 		.getOptions(..), .getCommands(..) and .getHandler(..) respectively???
 | ||||||
| // XXX should we handle <scriptName>-<command> script calls???
 | // XXX should we handle <scriptName>-<command> script calls???
 | ||||||
|  | // XXX might be a good idea to add handler.env = x to use the environment 
 | ||||||
|  | // 		variable x as the default value for option...
 | ||||||
|  | // 		...would also need to add this to -help as '(default: $VARIABLE_NAME)'
 | ||||||
|  | // XXX should this be split into BaseParser (base functionality) and 
 | ||||||
|  | // 		Parser (defaults)???
 | ||||||
| var Parser = | var Parser = | ||||||
| module.Parser = | module.Parser = | ||||||
| object.Constructor('Parser', { | object.Constructor('Parser', { | ||||||
| 	// config...
 | 	// config...
 | ||||||
| 	optionPrefix: '-', | 	optionPrefix: '-', | ||||||
| 	commandPrefix: '@', | 	commandPrefix: '@', | ||||||
| 	 |  | ||||||
| 	// NOTE: we only care about differentiating an option from a command
 | 	// NOTE: we only care about differentiating an option from a command
 | ||||||
| 	// 		here by design...
 | 	// 		here by design...
 | ||||||
| 	optionInputPattern: /^--?(.*)$/, | 	optionInputPattern: /^--?(.*)$/, | ||||||
| 	commandInputPattern: /^([a-zA-Z].*)$/, | 	commandInputPattern: /^([a-zA-Z].*)$/, | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	// instance stuff...
 | 	// instance stuff...
 | ||||||
| 	// XXX revise...
 | 	// XXX revise...
 | ||||||
| 	argv: null, | 	argv: null, | ||||||
| @ -164,11 +167,9 @@ object.Constructor('Parser', { | |||||||
| 			.map(function([e, _]){ return e }) }, | 			.map(function([e, _]){ return e }) }, | ||||||
| 	commands: function(){ | 	commands: function(){ | ||||||
| 		return this.options(this.commandPrefix) }, | 		return this.options(this.commandPrefix) }, | ||||||
| 
 |  | ||||||
| 	isCommand: function(str){ | 	isCommand: function(str){ | ||||||
| 		return this.commandInputPattern.test(str)  | 		return this.commandInputPattern.test(str)  | ||||||
| 			&& (this.commandPrefix + str) in this }, | 			&& (this.commandPrefix + str) in this }, | ||||||
| 
 |  | ||||||
| 	// NOTE: this ignores options forming alias loops and dead-end 
 | 	// NOTE: this ignores options forming alias loops and dead-end 
 | ||||||
| 	// 		options...
 | 	// 		options...
 | ||||||
| 	handler: function(key){ | 	handler: function(key){ | ||||||
| @ -193,15 +194,14 @@ object.Constructor('Parser', { | |||||||
| 				[] | 				[] | ||||||
| 				: ['dead-end'])] }, | 				: ['dead-end'])] }, | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	// XXX need to test option definitions... (???)
 | 	// XXX need to test option definitions... (???)
 | ||||||
| 	// 		i.e. report loops and dead ends...
 | 	// 		i.e. report loops and dead ends...
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	// doc stuff...
 | 	// doc stuff...
 | ||||||
| 	helpColumnOffset: 3, | 	helpColumnOffset: 3, | ||||||
| 	helpColumnPrefix: '- ', | 	helpColumnPrefix: '- ', | ||||||
| 
 | 
 | ||||||
|  | 	// doc sections...
 | ||||||
| 	usage: '$SCRIPTNAME [OPTIONS]', | 	usage: '$SCRIPTNAME [OPTIONS]', | ||||||
| 	doc: undefined, | 	doc: undefined, | ||||||
| 	examples: undefined, | 	examples: undefined, | ||||||
| @ -334,10 +334,21 @@ object.Constructor('Parser', { | |||||||
| 	// If this is false/undefined value is passed to the handler as-is...
 | 	// If this is false/undefined value is passed to the handler as-is...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// Example:
 | 	// Example:
 | ||||||
|  | 	// 		typeHandler: {
 | ||||||
|  | 	// 			int: parseInt,
 | ||||||
|  | 	// 			float: parseFloat,	
 | ||||||
|  | 	// 			number: function(v){ return new Number(v) },
 | ||||||
|  | 	// 			string: function(v){ return v.toString() },
 | ||||||
|  | 	// 			...
 | ||||||
|  | 	// 		},
 | ||||||
| 	//		handleArgumentValue: function(handler, value){
 | 	//		handleArgumentValue: function(handler, value){
 | ||||||
| 	//			// process handler value type definition or infer type 
 | 	//			var convert = this.typeHandler[handler.type]
 | ||||||
| 	//			// and convert...
 | 	//			return convert ?
 | ||||||
| 	//			return value },
 | 	//				convert(value)
 | ||||||
|  | 	//				: value },
 | ||||||
|  | 	//
 | ||||||
|  | 	// XXX would be nice to be able to collect arrays...
 | ||||||
|  | 	// XXX should we define a handler.Type handler???
 | ||||||
| 	handleArgumentValue: false, | 	handleArgumentValue: false, | ||||||
| 
 | 
 | ||||||
| 	// Handle error exit...
 | 	// Handle error exit...
 | ||||||
| @ -356,7 +367,6 @@ object.Constructor('Parser', { | |||||||
| 	// 	.error(callback(arg))
 | 	// 	.error(callback(arg))
 | ||||||
| 	//
 | 	//
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// XXX need to document the arguments to each handler/callback...
 |  | ||||||
| 	// XXX .then(..) passes the full list of unhandleed args including 
 | 	// XXX .then(..) passes the full list of unhandleed args including 
 | ||||||
| 	// 		argv[0] and argv[1]...
 | 	// 		argv[0] and argv[1]...
 | ||||||
| 	then: afterCallback('parsing'), | 	then: afterCallback('parsing'), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user