Browse files

Add option to limit to a single configuration.

  • Loading branch information...
1 parent 00e21f6 commit bb7cbdd38c071141154fd5a41bba6575d0dd8125 @sixten sixten committed Apr 17, 2012
Showing with 24 additions and 7 deletions.
  1. +2 −1 mogenerator.h
  2. +22 −6 mogenerator.m
View
3 mogenerator.h
@@ -17,7 +17,7 @@
#import "DDCommandLineInterface.h"
@interface NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
-- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_;
+- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString *)configuration_ verbose:(BOOL)verbose_;
@end
@interface NSEntityDescription (customBaseClass)
@@ -56,6 +56,7 @@
NSString *origModelBasePath;
NSString *tempMOMPath;
NSManagedObjectModel *model;
+ NSString *configuration;
NSString *baseClass;
NSString *baseClassForce;
NSString *includem;
View
28 mogenerator.m
@@ -31,14 +31,28 @@ - (NSDictionary *)fetchedPropertiesByName
@end
@implementation NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
-- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_ {
+- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString *)configuration_ verbose:(BOOL)verbose_ {
NSMutableArray *result = [NSMutableArray array];
+ NSArray* allEntities = nil;
- if(verbose_ && [[self entities] count] == 0){
- ddprintf(@"No entities found in model. No files will be generated.\n(model description: %@)\n", self);
+ if(nil == configuration_) {
+ allEntities = [self entities];
+ }
+ else if(NSNotFound != [[self configurations] indexOfObject:configuration_]){
+ allEntities = [self entitiesForConfiguration:configuration_];
+ }
+ else {
+ if(verbose_){
+ ddprintf(@"No configuration %@ found in model. No files will be generated.\n(model configurations: %@)\n", configuration_, [self configurations]);
+ }
+ return nil;
+ }
+
+ if(verbose_ && [allEntities count] == 0){
+ ddprintf(@"No entities found in model (or in specified configuration). No files will be generated.\n(model description: %@)\n", self);
}
- nsenumerate ([self entities], NSEntityDescription, entity) {
+ nsenumerate (allEntities, NSEntityDescription, entity) {
NSString *entityClassName = [entity managedObjectClassName];
if ([entityClassName isEqualToString:@"NSManagedObject"] || [entityClassName isEqualToString:gCustomBaseClass]){
@@ -458,6 +472,7 @@ - (void) application: (DDCliApplication *) app
{
// Long Short Argument options
{@"model", 'm', DDGetoptRequiredArgument},
+ {@"configuration", 'C', DDGetoptRequiredArgument},
{@"base-class", 0, DDGetoptRequiredArgument},
{@"base-class-force", 0, DDGetoptRequiredArgument},
// For compatibility:
@@ -487,6 +502,7 @@ - (void) printUsage;
ddprintf(@"%@: Usage [OPTIONS] <argument> [...]\n", DDCliApp);
printf("\n"
" -m, --model MODEL Path to model\n"
+ " -C, --configuration CONFIG Only consider entities included in the named configuration\n"
" --base-class CLASS Custom base class\n"
" --base-class-force CLASS Same as --base-class except will force all entities to have the specified base class. Even if a super entity exists\n"
" --includem FILE Generate aggregate include file for .m files for both human and machine generated source files\n"
@@ -695,7 +711,7 @@ - (int) application: (DDCliApplication *) app
}
}
}
- nsenumerate ([model entitiesWithACustomSubclassVerbose:NO], NSEntityDescription, entity) {
+ nsenumerate ([model entitiesWithACustomSubclassInConfiguration:configuration verbose:NO], NSEntityDescription, entity) {
[entityFilesByName removeObjectForKey:[entity managedObjectClassName]];
}
nsenumerate(entityFilesByName, NSSet, ophanedFiles) {
@@ -753,7 +769,7 @@ - (int) application: (DDCliApplication *) app
*machineMFiles = [NSMutableArray array],
*machineHFiles = [NSMutableArray array];
- nsenumerate ([model entitiesWithACustomSubclassVerbose:YES], NSEntityDescription, entity) {
+ nsenumerate ([model entitiesWithACustomSubclassInConfiguration:configuration verbose:YES], NSEntityDescription, entity) {
NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil];
NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil];
NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil];

0 comments on commit bb7cbdd

Please sign in to comment.