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

Support for overriding -D parameters with dot notation #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions jinja2cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def cli(opts, args):
sys.stderr.write("ERROR: unknown section. Exiting.")
return 1

data.update(parse_kv_string(opts.D or []))
data_update_from_kv_string(data, opts.D or [])

if opts.outfile is None:
out = sys.stdout
Expand All @@ -317,12 +317,23 @@ def cli(opts, args):
return 0


def parse_kv_string(pairs):
dict_ = {}
def data_update_from_kv_string(data, pairs):
for pair in pairs:
k, v = pair.split("=", 1)
dict_[force_text(k)] = force_text(v)
return dict_
k = force_text(k).split('.')
v = force_text(v)

last = None
current = data
for key in k:
last = current
current = current.get(key)
if current is None:
current = {}
last[key] = current

last[k[-1]] = v
return data


class LazyHelpOption(Option):
Expand Down