Permalink
Browse files

• Introduce -(NSDictionary)parameters method for CLIProxy

This will return parameters parsed as described here http://lists.macromates.com/textmate-dev/2008-September/012786.html

This commit doesn’t break backwards compatibility, since the old argument parsing stuff is still there, but the next commits will switch to this new interface and effectively break all commands using $DIALOG relying on the previous v2 interface.


git-svn-id: http://svn.textmate.org/branches/WIP/Tools/Dialog2@10560 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
1 parent 8283040 commit a24b76b87aab7171a731a44b6b65688a843dab62 @sorbits sorbits committed Sep 15, 2008
Showing with 34 additions and 0 deletions.
  1. +4 −0 CLIProxy.h
  2. +30 −0 CLIProxy.mm
View
4 CLIProxy.h
@@ -21,6 +21,8 @@
size_t optionCount;
NSArray* arguments;
NSDictionary* parsedOptions;
+
+ NSDictionary* parameters;
}
+ (id)proxyWithOptions:(NSDictionary*)options;
- (id)initWithOptions:(NSDictionary*)options;
@@ -29,6 +31,8 @@
- (void)writeStringToError:(NSString*)text;
- (id)readPropertyListFromInput;
+- (NSDictionary*)parameters;
+
- (NSFileHandle*)inputHandle;
- (NSFileHandle*)outputHandle;
- (NSFileHandle*)errorHandle;
View
30 CLIProxy.mm
@@ -40,9 +40,39 @@ - (void)dealloc
[arguments release];
[environment release];
[workingDirectory release];
+ [parameters release];
[super dealloc];
}
+- (NSDictionary*)parameters
+{
+ if(!parameters)
+ {
+ NSMutableDictionary* res = [NSMutableDictionary dictionary];
+ if(id plist = [TMDCommand readPropertyList:[self inputHandle] error:NULL])
+ {
+ if([plist isKindOfClass:[NSDictionary class]])
+ res = plist;
+ }
+
+ NSString* lastKey = nil;
+ for(size_t i = 2; i < [arguments count]; ++i)
+ {
+ NSString* arg = [arguments objectAtIndex:i];
+ BOOL isOption = [arg hasPrefix:@"--"];
+ if(lastKey)
+ [res setObject:(isOption ? [NSNull null] : arg) forKey:lastKey];
+ lastKey = isOption ? [arg substringFromIndex:2] : nil;
+ }
+
+ if(lastKey)
+ [res setObject:[NSNull null] forKey:lastKey];
+
+ parameters = [res retain];
+ }
+ return parameters;
+}
+
- (NSString*)workingDirectory
{
return workingDirectory;

0 comments on commit a24b76b

Please sign in to comment.