Uploaded image for project: 'Apache Freemarker'
  1. Apache Freemarker
  2. FREEMARKER-135

freemarker-generator-cli: Support user-supplied names for datasources

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None

    Description

      The current implementation of `freemarker-cli` provides all datasources as list to be rendered with the template. Individual datasources can be accessed via index or wildcard search based on the underlying file name. This forces the user to pass the datasources in the correct order when the template process more than on datasource or rely on file naming conventions.

      So we want to allow the naming of the datasources on the command line.

      A few thoughts along the line

      • A user might also want to provide additional metadata, e.g. `charset` or `mimetype`
      • We want to support positional parameters with `Picocli` so all that information should go into a single string

      The following usage should be supported

      # Single positional parameter 
      > freemarker-cli -t templates/info.ftl users.csv
      > freemarker-cli -t templates/info.ftl file:///users.csv
      
      # Multiple positional parameters
      > freemarker-cli -t templates/info.ftl users.csv transactions.csv
      > freemarker-cli -t templates/info.ftl users.csv file:///transactions.csv
      > freemarker-cli -t templates/info.ftl file:///users.csv file:///transactions.csv
      
      # Short option
      > freemarker-cli -t templates/info.ftl -d users.csv
      > freemarker-cli -t templates/info.ftl -d file:///users.csv
      > freemarker-cli -t templates/info.ftl -d file:///users.csv -d file:///transactions.csv
      
      # Long option
      > freemarker-cli -t templates/info.ftl --datasource users.csv
      > freemarker-cli -t templates/info.ftl --datasource file:///users.csv
      > freemarker-cli -t templates/info.ftl --datasource file:///users.csv --datasource file:///transactions.csv
      
      # Named datasource using file name
      > freemarker-cli -t templates/info.ftl users=users.csv
      > freemarker-cli -t templates/info.ftl -d users=users.csv
      > freemarker-cli -t templates/info.ftl --datasource users=users.csv
      
      # Named datasource using URI
      > freemarker-cli -t templates/info.ftl -d users=file:///users.csv
      > freemarker-cli -t templates/info.ftl --datasource users=users.csv
      
      # Named datasource using URI and fragments
      > freemarker-cli -t templates/info.ftl -d users=file:///users.csv#charset=UTF-16
      > freemarker-cli -t templates/info.ftl --datasource users=file:///users.csv#charset=UTF-16
      
      # Named datasource using URI and fragments with multiple parameters
      > freemarker-cli -t templates/info.ftl --datasource users=file:///users.csv#charset=UTF-16&mimetype=text/csv
      
      # Mix and match the various options
      > freemarker-cli -t templates/info.ftl --datasource users=file:///users.csv transactions=transactions.csv 
      

      As discusses on the mailing list some sort of grouping mechanism of `Datasource`s would be useful - the following usage should be supported

      # Define a group "admin"
      > freemarker-cli -t templates/info.ftl users-xxx:admin=site/sample/csv/some-user-file.csv
      > freemarker-cli -t templates/info.ftl -d users-xxx:admin=site/sample/csv/some-user-file.csv
      > freemarker-cli -t templates/info.ftl --datasource users-xxx:admin=site/sample/csv/some-user-file.csv
      

      Attachments

        Issue Links

          Activity

            People

              sgoeschl Siegfried Goeschl
              sgoeschl Siegfried Goeschl
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m