Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: parse -D parameters with dot notation #82

Open
nicklofaso opened this issue Sep 5, 2019 · 0 comments · May be fixed by #83
Open

Feature request: parse -D parameters with dot notation #82

nicklofaso opened this issue Sep 5, 2019 · 0 comments · May be fixed by #83

Comments

@nicklofaso
Copy link

Request

Currently it seems like -D parameter names are treated as a single value. It would be useful if the parameter used dot notation to parse it and allow it to be accessed the same way that the yaml parameters are.

See below for an example.

Example

test.tmpl

{
  foo: {{house.bathroom.size}}
  bar: {{house.kitchen.size}}
}

params.yaml

house:
  bathroom:
    size: 20

CLI Command

$ jinja2 test.tmpl params.yaml -D house.kitchen.value=55

Error Received

Traceback (most recent call last):
  File "/Users/nlofaso/.virtualenvs/platform-cdk/bin/jinja2", line 10, in <module>
    sys.exit(main())
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2cli/cli.py", line 424, in main
    sys.exit(cli(opts, args))
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2cli/cli.py", line 314, in cli
    out.write(render(template_path, data, extensions, opts.strict))
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2cli/cli.py", line 229, in render
    return env.get_template(os.path.basename(template_path)).render(data)
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/Users/nlofaso/tmp/test.tmpl", line 3, in top-level template code
    bar: {{house.kitchen.size}}
  File "/Users/nlofaso/.virtualenvs/platform-cdk/lib/python3.7/site-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'kitchen'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant