add ability for dynamic var file import
Opened this issue · 0 comments
If the user wants to run a template with multiple variable files, they need to supply each var file independently.
caster apply --var-file file1.yml --var-file file2.yml --var-file file3.yml
The user can also combine the files using a shell script and add those to a combined file
$varFileParams = gci .\folder\*.yml | foreach { "--var-file $_" } | join " "
caster apply $varFileParams
In order to simplify this process, the cli should support wildcard filters and perhaps a combination algorithm. Currently the combination algorithm is to override values when a property shares the same key. For code generation use cases, it would be desirable to combine the files into an array.
file1.yml
prop: 1
name: "hello"
only1: "only1"
file2.yml
prop: 2
name: "world"
only2: "only2"
Calling Caster Apply with the following var files would result in the data supplied to the template as
caster apply --var-file file1.yml --var-file file2.yml
data supplied to the template:
prop: 2
name: "world"
only1: "only1"
only2: "only2"
The user may want this data to be an array so the data supplied to the template could be:
- prop: 1
name: "hello"
only1: "only1"
- prop: 2
name: "world"
only2: "only2"
So perhaps a flag for combination behavior or a filter that is applied to file names that selects combination behavior for specific files?
# append attributes (top level)
caster apply --var-file-append file*.yml
# append attributes under path 'data'
cater apply --var-file-append data=file*.yml
# this should throw an error
caster apply --var key=value --var-file-append file*.yml
# merge attributes
caster apply --var-file file*.yml
An alternative syntax may be keeping var-flie and var but adding a jsonptr ':' prefix to show where the data gets placed into the resultant data file.
caster apply --var-file /data+:file*.yml
Recursive globs should be supported as well similar to .gitignore globs https://git-scm.com/docs/gitignore#_pattern_format
# search recursively current directory
caster apply --var-file **/*.yml
# search recursively in specific directory
caster apply --var-file child/**/*.yml