Index: utils/objfw-new/ObjFWNew.m ================================================================== --- utils/objfw-new/ObjFWNew.m +++ utils/objfw-new/ObjFWNew.m @@ -29,16 +29,30 @@ extern void newClass(OFString *, OFString *, OFMutableArray *); OF_APPLICATION_DELEGATE(ObjFWNew) static void -showUsage(void) +help(OFStream *stream, bool full, int status) { - [OFStdErr writeFormat: @"Usage: %@ --app|--class name\n", - [OFApplication programName]]; + [stream writeFormat: + @"Usage: %@ --app|--class [--superclass=] [--property=] name\n", + [OFApplication programName]]; + + if (full) { + [stream writeString: @"\n"]; + [stream writeLine: + @"Options:\n" + @" --app Create a new app\n" + @" --class Create a new class\n" + @" --help Show this help\n" + @" --superclass= Specify the superclass for the class\n" + @" --property= Add a property to the class.\n" + @" E.g.: --property='(readonly, " + @"nonatomic) id foo'"]; + } - [OFApplication terminateWithStatus: 1]; + [OFApplication terminateWithStatus: status]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching: (OFNotification *)notification { @@ -46,39 +60,46 @@ OFString *superclass = nil, *name; OFMutableArray OF_GENERIC(OFString *) *properties = nil; const OFOptionsParserOption options[] = { { 'a', @"app", 0, &app, NULL }, { 'c', @"class", 0, &class, NULL }, + { 'h', @"help", 0, NULL, NULL }, { 's', @"superclass", 1, NULL, &superclass }, { 'p', @"property", 1, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; + + if ([OFApplication arguments].count == 0) + help(OFStdErr, true, 1); optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { + case 'h': + help(OFStdOut, true, 0); + break; case 'p': if (properties == nil) properties = [OFMutableArray array]; [properties addObject: optionsParser.argument]; break; case '?': case ':': case '=': - showUsage(); + help(OFStdErr, false, 1); break; } } if ((app ^ class) != 1 || optionsParser.remainingArguments.count != 1) - showUsage(); + help(OFStdErr, false, 1); if ((superclass && !class) || (properties != nil && !class)) - showUsage(); + help(OFStdErr, false, 1); name = optionsParser.remainingArguments.firstObject; if ([name rangeOfString: @"."].location != OFNotFound) { [OFStdErr writeLine: @"Name must not contain dots!"]; [OFApplication terminate]; @@ -87,10 +108,10 @@ if (app) newApp(name); else if (class) newClass(name, superclass, properties); else - showUsage(); + help(OFStdErr, false, 1); [OFApplication terminate]; } @end