carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.68k stars 137 forks source link

About pass multiple key value without repeat --data-value-yaml #751

Closed buzzerpuzzle closed 2 years ago

buzzerpuzzle commented 2 years ago

Hi team!

I'm starting to explore the ytt technology recently and I have quick question about ytt related usage.

I know I could pass two parameter with something like below command.

ytt -f variable.yml --data-value-yaml test=123 --data-value-yaml test2=456

And I feel its kind of redundant cause I got to type two --data-value-yaml Therefore, I am wondering is there anyway I could make it something like below so that I don't need to mention --data-value-yaml twice

ytt -f variable.yml --data-value-yaml (test=123, test2=456) or ytt -f variable.yml --data-value-yaml {test=123, test2=456}

Thanks, Len

mamachanko commented 2 years ago

@buzzerpuzzle glad to hear about your interest in ytt.

To template YAML ytt can receive data values as you have discovered already. It offers a host of options for providing your values; those come roughly in two flavours:

Depending on your situation you want to pick one, but you can mix and match to fit your needs.

As for --data-value-yaml, it can only receive a single key. Let's say you have

#! test.yaml
#@ load("@ytt:data", "data")

values: #@ data.values

You could do

ytt -f test.yaml --data-value-yaml 'test={"test-1": "one", "test-2": "two"}'

and get

values:
  test:
    test-1: one
    test-2: two

But I suggest not to use --data-value-yaml as a general-purpose entry point for your values. Instead, I would like to refer you to "how to use data values" in the docs.

Feel free to ask more questions here, if you don't find that helpful! 🙇🏻

pivotaljohn commented 2 years ago

What a great answer, @mamachanko!!! So thorough! 🙇🏻

buzzerpuzzle commented 2 years ago

Thanks for this explanation, @mamachanko! In my case, I would probably need to add multiple KV and I might not able to get rid of multiple --data-value-yaml for this kind of case.