Index: utils/objfw-new/ObjFWNew.m ================================================================== --- utils/objfw-new/ObjFWNew.m +++ utils/objfw-new/ObjFWNew.m @@ -16,10 +16,11 @@ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFObject.h" +#import "OFOptionsParser.h" #import "OFStdIOStream.h" #import "OFString.h" @interface ObjFWNew: OFObject @end @@ -30,33 +31,41 @@ OF_APPLICATION_DELEGATE(ObjFWNew) static void showUsage(void) { - [OFStdErr writeFormat: @"Usage: %@ app|class name [properties]\n", + [OFStdErr writeFormat: @"Usage: %@ --app|--class name\n", [OFApplication programName]]; [OFApplication terminateWithStatus: 1]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching { - OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments]; - OFString *type, *name; + bool app, class; + const OFOptionsParserOption options[] = { + { '\0', @"app", 0, &app, NULL }, + { '\0', @"class", 0, &class, NULL }, + { '\0', nil, 0, NULL, NULL } + }; + OFOptionsParser *optionsParser; + OFUnichar option; + + optionsParser = [OFOptionsParser parserWithOptions: options]; + while ((option = [optionsParser nextOption]) != '\0') + if (option == '?') + showUsage(); - if (arguments.count != 2) + if ((app ^ class) != 1 || optionsParser.remainingArguments.count != 1) showUsage(); - type = [arguments objectAtIndex: 0]; - name = [arguments objectAtIndex: 1]; - - if ([type isEqual: @"app"]) - newApp(name); - else if ([type isEqual: @"class"]) - newClass(name); + if (app) + newApp(optionsParser.remainingArguments.firstObject); + else if (class) + newClass(optionsParser.remainingArguments.firstObject); else showUsage(); [OFApplication terminate]; } @end