How do the Mogenerator parameters work, which can I send via Xcode? [closed]
Asked Answered
I

4

68

The help for Mogenerator is very minimal. What do all the parameters do?

Impetuosity answered 28/8, 2010 at 2:49 Comment(0)
I
149

Parameters that work both via the command line utility and Xcode:

  • --base-class: The name af the base class which the "private class" (e.g. _MyObject.h) will inherit from. This will also add an import in the form of #import "MyManagedObject.h" to the same .h file. Tip: if the class you want to inherit from is located in a library, the default import statement won't work. As a workaround, you could have an extra level of inheritance for each project you create and have that class inherit from the library on (e.g. set the base class to MyProjectManagedObject which you create manually and inherit from MyLibManagedObject).
  • --template-path: The path to where the 4 .motemplate files are located. When this is not provided, it will look at all the "app support directories" (e.g. "/Library/Application Support/mogenerator/").
  • --template-group: A subdirectory name underneath the template-path directory to use.
  • --template-var arc=true: Required for the generated files to compile while using ARC.
  • --output-dir: The output directory for all generated files.
  • --machine-dir: The directory where the _<class>.h and _<class>.m will be output to. If --output-dir is also defined, this parameter takes precedence.
  • --human-dir: The directory where the <class>.h and <class>.m will be output to. If --output-dir is also defined, this parameter takes precedence.
  • --includem: the full path to a file that will include all the #import for all the .h files that are created. This file does not need to exist (i.e. it will be created for you if it doesn't). This file, will not be included in the project automatically for you. You must include it manually by dragging it into the Groups & Files list of your project.

Using relative paths in Xcode for any of the above arguments won't work since the working directory is set to one of the root directories of the system (e.g. Applications, Developer, Library, or System). (I haven't had enough time to figure out which one of these it is exactly.)

Parameters that cannot be used in Xcode:

  • --model: The path to the .xcdatamodel file, cannot be set in Xcode.
  • --list-source-files
  • --orphaned
  • --versioned
  • --help

Running and sending parameters to xmod via Xcode:

(Update: I haven't tried this on Xcode 4, only Xcode 3. For Xcode 4, you can add mogenerator as a build phase instead of following the following steps.)

  1. Go to the info page of the .xcdatamodel file.
  2. Choose the Comments tab.
  3. Add xmod to the comments field, on its own line.
  4. Every time you save the model, it will regenerate the machine files for you.

To send parameters, they must be on their own line(s):

This works:

xmod
--base-class CLASS
--template-path PATH

And even this works:

xmod
--base-class CLASS --template-path PATH

But, this won't work:

xmod --base-class CLASS --template-path PATH

Note: You must close the Info window for the settings to take effect.

Impetuosity answered 28/8, 2010 at 2:50 Comment(8)
Nice job, I'll link this from the project's homepage :-)Tami
I find that xmod is not respecting my output arguments. Yes, they are on a separate line. First it fails to generate files because the folder it wants (named after the model) isn't there, although it makes the folder anyway. Then if I try again, it creates the files in the folder file which it created, then adds a group to Xcode with that name, which I also don't want.Adverse
Note: if you installed mogenerator via homebrew, it will be located in /usr/local/bin which is NOT in Xcode's default PATH. To make it work, add PATH=${PATH}:/usr/local/bin as the first line of your script.Fredelia
It might be worth adding --template-var arc=true which is required for the generated code to work with ARCKenney
Can't seem to find the info page of the .xcdatamodel file. Any screenshots on how to get to it?Ophthalmologist
Shouldn't this be in mogenerator's Readme on GitHub? github.com/rentzsch/mogenerator Pointing to a Stack Overflow post seems to be a tenuous documentation method. :)Anklet
Has the location of the templates changed? There is no directory at /Library/Application Support/mogenerator/Purim
is -O an alias for --output-dir?Heliotaxis
A
6

As of XCode 4, the Info window is no longer available, so don't be concerned if you can't set it up as answered above.

Use John Blanco's guide to set up a scripting target which allows you to pass command-line arguments directly to mogenerator. Note that you might have to tweak the paths in his example slightly... toss a pwd in the script and check the paths against the script's working directory if it doesn't run for you right away.

For a list of available command-line arguments, run mogenerator --help in the Terminal. AFAICT, all of them work from the scripting step.

See this answer for another way to invoke mogenerator via a "pre-action" if you want to automatically rebuild your machine files with every build. There's also a good tip on putting a mogenerator script into your VCS.

Antonetta answered 15/2, 2013 at 23:27 Comment(1)
Excellent answer. Thank you. I linked to this from here: https://mcmap.net/q/282118/-how-do-i-use-mogenerator/…Stain
C
1

Here is the output from --help as of version 1.27

mogenerator: Usage [OPTIONS] <argument> [...]

  -m, --model MODEL             Path to model
  -C, --configuration CONFIG    Only consider entities included in the named configuration
      --base-class CLASS        Custom base class
      --base-class-import TEXT        Imports base class as #import TEXT
      --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
      --includem FILE           Generate aggregate include file for .m files for both human and machine generated source files
      --includeh FILE           Generate aggregate include file for .h files for human generated source files only
      --template-path PATH      Path to templates (absolute or relative to model path)
      --template-group NAME     Name of template group
      --template-var KEY=VALUE  A key-value pair to pass to the template file. There can be many of these.
  -O, --output-dir DIR          Output directory
  -M, --machine-dir DIR         Output directory for machine files
  -H, --human-dir DIR           Output directory for human files
      --list-source-files       Only list model-related source files
      --orphaned                Only list files whose entities no longer exist
      --version                 Display version and exit
  -h, --help                    Display this help and exit

Implements generation gap codegen pattern for Core Data.
Inspired by eogenerator.
Crematorium answered 22/8, 2013 at 17:58 Comment(0)
F
0

Also, maybe will be helpful. For determining which params can be used for

--template-var KEY=VALUE

open *.motemplate file, and find string like "TemplateVar." after point you will see parameter name and will able to understand what it do.

This params has built-in template

--template-var arc=true 
--template-var frc=true
--template-var modules=true
Feldt answered 29/6, 2014 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.