wrouesnel / p2cli

pongo2 cli - like the j2cli package in python, but compiles to self-contained go executables
GNU General Public License v2.0
87 stars 20 forks source link

Multiple file templating example threw error while testing #10

Closed vijayaji closed 6 years ago

vijayaji commented 6 years ago

While testing the multiple file templating example I faced below errors.

# p2 --enable-write_file -t template.p2 -i input.yml
Error: Invalid trailing arguments: [--enable-write_file -t template.p2 -i input.yml]
Usage: p2 [global options]

Global options:
        -h, --help                Show this help
        -v, --version             Print version
        -d, --debug               Print Go serialization to stderr
        -f, --format              Input data format [valid values: env,yaml,json]
            --use-env-key         Treat --input as an environment key name to read.
        -t, --template            Template file to process
        -i, --input               Input data path. Leave blank for stdin.
        -o, --output              Output file. Leave blank for stdout.
            --enable-filters      Enable custom p2 filters.
            --enable-noop-filters Enable all custom filters in noop mode. Supercedes --enable-filters

I had to run below to avoid the error. #p2 -t template.p2 -i input.yml --enable-filters write_file

Also the input.yml and template.p2 seemed to have wrong content. Had to re-write to below to get the desired output.

users:
- user:
  name: Mike
  content: This is Mike's content.

- user:
  name: Sally
  content: This is Sally's content.

- user:
  name: Greg
  content: This is Greg's content.  

template.p2

{% macro user_content(content) %}
{{content|safe}}
{% endmacro %}

{% for user in users %}
##  {{user.name}}.txt output
{% set filename = user.name|stringformat:"%s.txt" %}
{{ user_content( user.content ) | write_file:filename }}
##
{% endfor %}

If this is ok shall I raise a PR to fix this in the readme?

wrouesnel commented 6 years ago

Absolutely!

vijayaji commented 6 years ago

Raised PR https://github.com/wrouesnel/p2cli/pull/11