You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Siegfried Goeschl (Jira)" <ji...@apache.org> on 2020/11/02 18:48:00 UTC
[jira] [Commented] (FREEMARKER-161) [freemarker-generator] Allow
multiple transformations on the CLI
[ https://issues.apache.org/jira/browse/FREEMARKER-161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17224881#comment-17224881 ]
Siegfried Goeschl commented on FREEMARKER-161:
----------------------------------------------
Played around with picocli and that is mostly working
{code:java}
package org.apache.freemarker.generator.cli.config;
import org.apache.commons.lang3.Validate;
import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import java.util.List;
@Command(name = "repeating-composite-demo")
public class CompositeGroupDemo {
@ArgGroup(exclusive = false, multiplicity = "1..*")
List<OutputGenerator> outputGenerators;
static class OutputDefinition {
@Option(names = { "-o", "--output" }, description = "output files or directories") List<String> outputs;
}
static class DataSourceDefinition {
@Option(names = { "-s", "--data-source" }, description = "data source used for rendering") List<String> dataSources;
}
static class TemplateDefinition {
@Option(names = { "-t", "--template" }, description = "templates to process") String template;
@Option(names = { "-i", "--interactive" }, description = "interactive template to process") public String interactiveTemplate;
}
static class OutputGenerator {
@ArgGroup(multiplicity = "1")
TemplateDefinition templateDefinition;
@ArgGroup(exclusive = false)
DataSourceDefinition dataSourceDefinition;
@ArgGroup(exclusive = false)
OutputDefinition outputDefinition;
}
public static void main(String[] args) {
final CompositeGroupDemo compositeGroupDemo = new CompositeGroupDemo();
final CommandLine cmd = new CommandLine(compositeGroupDemo);
cmd.parseArgs(
"-t", "template01.ftl", "-s", "datasource10.csv",
"-t", "template02.ftl", "-s", "datasource20.csv", "-s", "datasource21.csv",
"-i", "some-interactive-template", "-s", "datasource30.csv", "-o", "out.txt",
"-i", "some-interactive-template"
);
final List<OutputGenerator> outputGenerators = compositeGroupDemo.outputGenerators;
Validate.notNull(outputGenerators);
Validate.isTrue(outputGenerators.size() == 4);
Validate.isTrue(outputGenerators.get(0).templateDefinition.template.equals("template01.ftl"));
Validate.isTrue(outputGenerators.get(0).dataSourceDefinition.dataSources.size() == 1);
Validate.isTrue(outputGenerators.get(0).dataSourceDefinition.dataSources.get(0).equals("datasource10.csv"));
Validate.isTrue(outputGenerators.get(0).outputDefinition == null);
Validate.isTrue(outputGenerators.get(1).templateDefinition.template.equals("template02.ftl"));
Validate.isTrue(outputGenerators.get(1).dataSourceDefinition.dataSources.size() == 2);
Validate.isTrue(outputGenerators.get(1).dataSourceDefinition.dataSources.get(0).equals("datasource20.csv"));
Validate.isTrue(outputGenerators.get(1).dataSourceDefinition.dataSources.get(1).equals("datasource21.csv"));
Validate.isTrue(outputGenerators.get(0).outputDefinition == null);
Validate.isTrue(outputGenerators.get(2).templateDefinition.interactiveTemplate.equals("some-interactive-template"));
Validate.isTrue(outputGenerators.get(2).dataSourceDefinition.dataSources.size() == 1);
Validate.isTrue(outputGenerators.get(2).dataSourceDefinition.dataSources.get(0).equals("datasource30.csv"));
Validate.isTrue(outputGenerators.get(2).outputDefinition.outputs.get(0).equals("out.txt"));
Validate.isTrue(outputGenerators.get(3).templateDefinition.interactiveTemplate.equals("some-interactive-template"));
return;
}
}
{code}
> [freemarker-generator] Allow multiple transformations on the CLI
> ----------------------------------------------------------------
>
> Key: FREEMARKER-161
> URL: https://issues.apache.org/jira/browse/FREEMARKER-161
> Project: Apache Freemarker
> Issue Type: Task
> Reporter: Siegfried Goeschl
> Assignee: Siegfried Goeschl
> Priority: Major
>
> Currently freemarker-cli allows to transform
> * a single template using 0-n data source => file/stdout
> * multiple templates using 0-n shared data sources => files/stdout
> * a directory of templates using 0-n shared data sources => directory/stdout
> {noformat}
> # Transforming a directory of templates using 0-n shared data sources
> freemarker-cli -t site/template/ -m nginx.env
> # Transforming multiple templates using 0-n shared data sources
> freemarker-cli \
> -t templates/csv/md/transform.ftl -o target/contract.md \
> -t templates/csv/html/transform.ftl -o target/contract.html \
> examples/data/csv/contract.csv
> {noformat}
> According to [~ddekany@freemail.hu] it would be nice to support the transformation of multiple templates using individual set of data sources
> {noformat}
> freemarker-cli \
> -t templates/template01.ftl -s datsource010.json -o target/template01.xyz \
> -t templates/template02.ftl -s datsource020.json -s datsource020.json -o target/template02.xyz
> {noformat}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)