kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.58k stars 113 forks source link

Is there any way to dynamically override imported file's value? #1548

Closed masato-io closed 1 month ago

masato-io commented 1 month ago

General Question

Let's say I have these two files:

workspace.k

import applications.app

schema Service:
    name: str

schema Workspace:
    apps: [app.App]

workspace = Workspace {
    apps: [
        app.starwars
        app.godfather
    ]
}

app.k

schema App:
    name: str

starwars = App {name: "starwars"}

godfather = App {name: "godfather"}

Now, I'm wondering if there is any way to change app.k's starwars .name to xyz by only reading workspace.k file (knowing example below won't work.).

E.g.,

kcl workspace.k -O app.starwars.name="'xyz'" -d

Any elaboration would be appreciated.

Peefy commented 1 month ago

At present, only modifying files in the main package is supported at the CLI level, and any KCL file can be modified through the OverrideFile API like https://www.kcl-lang.io/docs/user_docs/guides/automation#3-use-kcl-api-for-automation or https://www.kcl-lang.io/docs/reference/xlang-api/overview

masato-io commented 1 month ago

Understood, appreciate the clarifications. Will look into API stuff more & closing the issue 🙏