Command line arguments with no variable don't crash the app.

This commit is contained in:
Corey Johnson 2012-09-18 16:49:27 -07:00
parent 96e2a66065
commit a1939da395

View File

@ -31,7 +31,6 @@
int opt; int opt;
int longindex; int longindex;
if (argc > 2 && strcmp(argv[argc - 2], "-NSDocumentRevisionsDebugMode") == 0) { // Because Xcode inserts useless command-line args by default: http://trac.wxwidgets.org/ticket/13732 if (argc > 2 && strcmp(argv[argc - 2], "-NSDocumentRevisionsDebugMode") == 0) { // Because Xcode inserts useless command-line args by default: http://trac.wxwidgets.org/ticket/13732
argc -= 2; // Ignore last two arguments argc -= 2; // Ignore last two arguments
} }
@ -43,10 +42,10 @@
{ "test", optional_argument, NULL, 't' }, { "test", optional_argument, NULL, 't' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
while ((opt = getopt_long(argc, argv, "r:K:bth?", longopts, &longindex)) != -1) { while ((opt = getopt_long(argc, argv, "r:K:bth?", longopts, &longindex)) != -1) {
NSString *key = [NSString stringWithUTF8String:longopts[longindex].name]; NSString *key = [NSString stringWithUTF8String:longopts[longindex].name];
NSString *value = [NSString stringWithUTF8String:optarg]; NSString *value = optarg ? [NSString stringWithUTF8String:optarg] : @"YES";
switch (opt) { switch (opt) {
case 'K': case 'K':
@ -56,7 +55,7 @@
[arguments setObject:value forKey:key]; [arguments setObject:value forKey:key];
break; break;
default: default:
printf("usage: atom [--resource-path=<path>] [<path>]"); NSLog(@"usage: atom [--resource-path=<path>] [<path>]");
} }
} }
@ -73,6 +72,7 @@
[arguments setObject:path forKey:@"path"]; [arguments setObject:path forKey:@"path"];
} }
return arguments; return arguments;
} }
@ -134,7 +134,7 @@
- (void)applicationWillFinishLaunching:(NSNotification *)notification { - (void)applicationWillFinishLaunching:(NSNotification *)notification {
_backgroundWindowController = [[AtomWindowController alloc] initInBackground]; _backgroundWindowController = [[AtomWindowController alloc] initInBackground];
if ([self.arguments objectForKey:@"benchmark"]) { if ([self.arguments objectForKey:@"benchmark"]) {
[self runBenchmarksThenExit:true]; [self runBenchmarksThenExit:true];
} }