Skip to content

Templating File Systems in Pkl #777

Answered by HT154
ghyatzo asked this question in Q&A
Nov 4, 2024 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

@holzensp's advice here is spot on!

Filesystem modeling is tough in Pkl in my experience because of the lack of recursive typealiases. Here's how you can go about it (today, and with currently-not-possible ideal solution in comments):

typealias Directory = Mapping<String, Any?>
// in a hypothetical future where recursive typealiases exist
// typealias Directory = Mapping<String, (*Directory|String)?>

rootDir: Directory = new {
  ["obj1"] = new Directory { // in that hypothetical future, this can be just `["obj1"] {`
    ["inner1"] = "inner1 content"
    ["inner2"] = "inner2 content"
    ["obj1_mirror"] = (this) {
      ["obj1_mirror"] = null
    }
  }
}

output {
  files {
    ...flatten…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@ghyatzo
Comment options

@holzensp
Comment options

@ghyatzo
Comment options

@HT154
Comment options

Answer selected by ghyatzo
@ghyatzo
Comment options

@holzensp
Comment options

@ghyatzo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants