diff --git a/examples/data-values/expected.txt b/examples/data-values/expected.txt index 45b4df99..fa175227 100644 --- a/examples/data-values/expected.txt +++ b/examples/data-values/expected.txt @@ -33,3 +33,14 @@ string: str bool: true int: 124 float: 0 +*** +nothing: something +string: |- + Value that comes from a file. + + Typically, useful for files that contain values + that should just be passed through to system + configuration, wholesale (e.g. certs). +bool: false +int: 0 +float: 0 \ No newline at end of file diff --git a/examples/data-values/file-as-value.txt b/examples/data-values/file-as-value.txt new file mode 100644 index 00000000..40cade73 --- /dev/null +++ b/examples/data-values/file-as-value.txt @@ -0,0 +1,5 @@ +Value that comes from a file. + +Typically, useful for files that contain values +that should just be passed through to system +configuration, wholesale (e.g. certs). \ No newline at end of file diff --git a/examples/data-values/run.sh b/examples/data-values/run.sh index a88adaf2..fa1fcdbe 100755 --- a/examples/data-values/run.sh +++ b/examples/data-values/run.sh @@ -42,3 +42,8 @@ echo '***' ./ytt -f examples/data-values/config.yml -f examples/data-values/values.yml \ --data-values-file examples/data-values/values-file.yml + +echo '***' + +./ytt -f examples/data-values/config.yml -f examples/data-values/values.yml \ + --data-value-file string=examples/data-values/file-as-value.txt diff --git a/pkg/cmd/template/data_values_flags.go b/pkg/cmd/template/data_values_flags.go index 68074945..169811b1 100644 --- a/pkg/cmd/template/data_values_flags.go +++ b/pkg/cmd/template/data_values_flags.go @@ -53,7 +53,7 @@ func (s *DataValuesFlags) Set(cmdFlags CmdFlags) { cmdFlags.StringArrayVarP(&s.KVsFromStrings, "data-value", "v", nil, "Set specific data value to given value, as string (format: all.key1.subkey=123) (can be specified multiple times)") cmdFlags.StringArrayVar(&s.KVsFromYAML, "data-value-yaml", nil, "Set specific data value to given value, parsed as YAML (format: all.key1.subkey=true) (can be specified multiple times)") - cmdFlags.StringArrayVar(&s.FromFiles, "data-value-file", nil, "Set specific data value to contents of a file (format: [@lib1:]all.key1.subkey={file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)") + cmdFlags.StringArrayVar(&s.KVsFromFiles, "data-value-file", nil, "Set specific data value to contents of a file (format: [@lib1:]all.key1.subkey={file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)") cmdFlags.StringArrayVar(&s.FromFiles, "data-values-file", nil, "Set multiple data values via plain YAML files (format: [@lib1:]{file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)") cmdFlags.BoolVar(&s.Inspect, "data-values-inspect", false, "Determine the final data values (applying any overlays) and display that result") diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 991f0064..3be73059 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -116,6 +116,26 @@ float: 123.123 require.Equal(t, string(expectedOutput), actualOutput) }) + t.Run("--data-value-file flag", func(t *testing.T) { + flags := yttFlags{ + {"--data-value-file": "string=../../examples/data-values/file-as-value.txt"}, + } + actualOutput := runYtt(t, testInputFiles{"../../examples/data-values/config.yml", "../../examples/data-values/values.yml"}, "", flags, nil) + expectedOutput := `nothing: something +string: |- + Value that comes from a file. + + Typically, useful for files that contain values + that should just be passed through to system + configuration, wholesale (e.g. certs). +bool: false +int: 0 +float: 0 +` + + require.Equal(t, expectedOutput, actualOutput) + }) + }) t.Run("can be 'required'", func(t *testing.T) { expectedFileOutput, err := ioutil.ReadFile("../../examples/data-values-required/expected.txt")