Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the attempt to parse out the value type in a key/value argument…

… pair.

	* Supports true/false
	* Supports numbers
	* Otherwise just a string
  • Loading branch information...
commit 7078754670f445f62a660dbd28a85497c80483a0 1 parent a2bb6db
extremeboredom authored
Showing with 23 additions and 1 deletion.
  1. +23 −1 ddcli/DDGetoptLongParser.m
24 ddcli/DDGetoptLongParser.m
View
@@ -226,7 +226,29 @@ - (NSArray *) parseOptionsWithArguments: (NSArray *) arguments
NSArray *pair = [nsoptarg componentsSeparatedByString:@"="];
// Build a keypath from the argument and the new key
NSString *keypath = [NSString stringWithFormat:@"%@.%@", key, [pair objectAtIndex:0]];
- [mTarget setValue:[pair objectAtIndex:1] forKeyPath:keypath];
+
+ // If it is a number or a boolean, we'll parse that out
+ NSString *value = [pair objectAtIndex:1];
+ id parsedValue = value;
+ // Looks like a boolean?
+ if ([value isCaseInsensitiveLike:@"true"] || [value isCaseInsensitiveLike:@"false"])
+ {
+ parsedValue = [NSNumber numberWithBool:[value boolValue]];
+ }
+ else
+ {
+ // Looks like a number?
+ NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
+ [formatter setAllowsFloats:YES];
+ NSNumber *numberValue = [formatter numberFromString:value];
+ if (numberValue)
+ {
+ parsedValue = numberValue;
+ }
+ [formatter release];
+ }
+
+ [mTarget setValue:parsedValue forKeyPath:keypath];
}
else
[mTarget setValue: nsoptarg forKey: key];
Please sign in to comment.
Something went wrong with that request. Please try again.