Use fmpp command line parameter in template

366 Views Asked by At

I have some configuration templates which use FMPP to generate the real runtime config files based upon info in a csv and properties file (defined in config.fmpp).

I want to be able to configure a second cluster server for the same task using the same set of templates and config.fmpp information. However, there are slight differences needed in the generated runtime config and I can do this if I know which server instance I am on ("serverA" or "serverB") using a standard fmpp variable like ${myserver}.

But there must only be one set of templates and FMPP config files so I need to somehow get the value of "myserver" from the runtime environment in each server.

Some of the options I might have are:

  • pass value of myserver on the command line tool invocation (best way); or
  • get it from an environment variable.

Does anyone have an example of the code to do any of these and any suggestions of the best approach? Online reference would be great.

fmpp -S /home/me/sample-project/src -Param myserver:serverA

Environment settings:

  • fmpp v0.9.14
  • freemarker v2.3.19
1

There are 1 best solutions below

4
ddekany On

Use the -D command line option (see --help):

-D, --data=<TDD>  Creates shared data that all templates will see. <TDD> is the
                  Textual Data Definition, e.g.:
                  -D "properties(style.properties), onLine:true"
                  Note that paths like "style.properties" are relative to the
                  data root directory.

Like:

fmpp -S /home/me/sample-project/src -D myserver:serverA

Note that there's a space after the -D. (It's not like the java command line syntax, but rather like the standard GNU command line syntax.

This -D has nothing to do with Java's -D option.

The documentation shows onLine:true, but such Boolean values are legacy and no longer accepted. Use online:yes to parse Boolean values.

For example:

fmpp \
  -S /path/ \
  --verbose \
  -D "online:yes"

Then, within the template:

<p>
  online: ${online}
</p>

Will result in:

online: yes

The --verbose command-line parameter is useful to show any errors when parsing the template.