Open fchastanet opened 1 month ago
I finally fix the issue by slightly changing my k file to accept a yaml file as option that I can read
import regex
import yaml
import file
configFile = option(key="configFile", type='str', required=True, help="load config file")
schema BinFileSchema:
vars?: VarsSchema
compilerConfig?: CompilerConfigSchema
binData: BinDataSchema
test: str = "toto"
schema BinDataSchema:
commands: CommandsSchema
schema CompilerConfigSchema:
test: str = "toto"
schema DefaultCommandSchema:
mainFile?: str
definitionFiles?: [DefinitionFilesSchema]
check:
definitionFiles and isunique([ int(_x["order"]) \
for _, _x in definitionFiles]) if definitionFiles, \
"definitionFiles: order property value should be unique, check for duplicates"
schema CommandsSchema:
default: DefaultCommandSchema
schema DefinitionFilesSchema:
file: str
order: int
check:
order > 0, "order must >0"
schema VarsSchema:
[attr: str]: str
check:
regex.match(attr, r'^[A-Z0-9_]+$')
configYaml:BinFileSchema = yaml.decode(file.read(configFile))
yaml.encode(configYaml)
Then the command
kcl binFile.k --format yaml -D configFile=data.yaml
is it the right way to go ? is there a simple way ? Can I suggest you to provide a help page for the ones that are migrating from cue or other tools with recipes to migrate.
Because KCL is not completely power-law like CUE, it does not support directly inputting YAML/JSON files at the command line. It is more like using CUE's @embed
to input YAML/JSON in KCL to use file.read
. Providing help with migrating from CUE to KCL or a concept comparison document is a good suggestion 👍.
General Question
Hello,
Maybe I didn't get the aim of your tool. I found the way to validate my yaml file
with this k file
Using the validation command:
kcl vet testsKcl/data.yaml binFile.k --format yaml
it works very well
but I didn't find the right command or ability to import my yaml file to be processed by the k file in order to interpolate the default properties that would be missing from my yaml file (eg: the test properties of the k file).
I tried several commands but no success to generate any viable output:
kcl run data.yaml binFile.k --format yaml
Here I get an empty output
{}
The command
kcl -Y data.yaml binFile.k --format yaml
gives{}
as wellwhat am I missing ?
kind regards