Skip to content

howto_Cobigen CLI generation

travis edited this page Oct 23, 2019 · 24 revisions

Cobigen Command line Interface generation

Our new command line interface (CLI) for CobiGen enables the generation of code using few commands. This feature allows us to decouple CobiGen from Eclipse.

Commands and options

Using the following command and option you will be able to customize your generation as follows:

  • cobigen, cg: Main entry point of the CLI. If no arguments are passed, man page will be printed.

  • [generate, g]: Command used for code generation.

    • InputGlob: Glob pattern of the input file or the whole path of the input file from which the code will be generated.

    • < --increment, -i > : Specifies an increment ID to be generated. You can also search increments by name and CobiGen will output the resultant list.

    • < --template, -t > : specifies a template ID to be generated. You can also search templates by name and CobiGen will output the resultant list.

    • < --outputRootPath, -out >: The project file path in which you want to generate your code. If no output path is given, CobiGen will use the project of your input file.

  • < --verbose, -v > : Prints debug information, verbose log.

  • < --help, -h > : Prints man page.

  • < update, u> : This command compare the artificial pom plug-ins version with central latest version available and user can update any outdated plug-ins version .

CLI Execution steps:

CobiGen CLI is installed inside your devonfw distribution. In order to execute it follow the next steps:

  1. Run console.bat, this will open a console.

  2. Execute cobigen or cg and the man page should be printed.

  3. Use a valid CobiGen input file and run cobigen generate <pathToInputFile>. Note: On the first execution of the CLI, CobiGen will download all the needed dependencies, please be patient.

  4. A list of increments will be printed so that you can start the generation.

Preview of the man page for generate command:

Generation path

Examples

A selection of commands that you can use with the CLI:

  • cobigen generate foo\bar\EmployeeEntity.java: As no output path has been defined, CobiGen will try to find the pom.xml of the current project in order to set the generation root path.

  • cobigen generate foo\bar\*.java --out other\project: Will retrieve all the Java files on that input folder and generate the code on the path specified by --out.

  • cg g foo\bar\webServices.yml --increment TO: Performs a string search using TO and will print the closest increments like in the following image:

Generation path
  • cg g foo\bar\webServices.yml -i 1,4,6: Directly generates increments with IDs 1, 4 and 6. CobiGen will not request you any other input.

CLI update command

Example of Update Command :

Generation path

Select the plug-ins which you want to update like below :

Generation path

Troubleshooting

When generating code from a Java file, CobiGen makes use of Java reflection for generating templates. In order to do that, the CLI needs to find the compiled source code of your project.

If you find an error like Compiled class foo\bar\EmployeeEntity.java has not been found, it means you need to run mvn clean install on the input project so that a new target folder gets created with the needed compiled sources.

Clone this wiki locally