Commits

Mathias Panzenböck  committed f85c150

fixed stringifyAny, enum and comments of onOption and stringify

  • Participants
  • Parent commits 6e89c8a

Comments (0)

Files changed (1)

  *                   short list of details shown in braces after the option name
  *                   e.g. integer type options add 'base: '+base if base !== undefined
  *      metavar:     string or array, per deflault inferred from type
- *      onOption:    function (value, ...) -> boolean, optional
+ *      onOption:    function (value) -> boolean, optional
  *                   Returning true canceles any further option parsing
  *                   and the parse() method returns null.
  *
  *                   Number of required arguments.
  *                   -1 means one optional argument.
  *      parse:       function (string, ...) -> value
- *      stringify:   function (value, ...) -> string, optional
+ *      stringify:   function (value) -> string, optional
  *   }
  *
  * ===== Option-Arguments =====
 		if (optdef.values instanceof Array) {
 			for (i in optdef.values) {
 				var value = optdef.values[i];
-				values[optdef.ignoreCase ? value.toLowerCase() : value] = value;
+				var label = String(value);
+				values[optdef.ignoreCase ? label.toLowerCase() : label] = value;
 				labels.push(optdef.stringify(value));
 			}
 		}
 	return ''+value;
 }
 
-function stringifyAny () {
-	var buf = [];
-	for (i in arguments) {
-		var arg = arguments[i];
-		if (arg instanceof Array) {
-			arg = optdef.stringify.apply(optdef,arg);
+function stringifyAny (value) {
+	if (value instanceof Array) {
+		var buf = [];
+		for (i in value) {
+			buf.push(stringifyAny(value[i]));
 		}
-		else if (typeof(arg) == 'string') {
-			arg = stringifyString(arg);
-		}
-		else {
-			arg += '';
-		}
-		buf.push(arg);
+		return buf.join(' ');
 	}
-	return buf.join(' ');
+	else if (typeof(value) == 'string') {
+		return stringifyString(value);
+	}
+	else {
+		return String(value);
+	}
 }
 
 function stringifyInteger (value) {