Skip to content

How to overwrite with default value from outside a class #382

Answered by odenix
dkyanakiev asked this question in Q&A
Discussion options

You must be logged in to vote

I think this is how it's done in Pkl. The main trick is to leverage Listing.default by setting rules.default in basealerts.pkl and using new { instead of new SingleAlert { in alerts.pkl:

channelDefault: String = "#chanel #tmp-channel"

usersDefault: String = "@me"

groups: Alerts = new {
  rules {
    default {
      annotations {
        ["channel"] = channelDefault
        ["users"] = usersDefault
      }
    }
  }
}

class Alerts {
  name: String
  rules: Listing<SingleAlert>
}

class SingleAlert {
  name: String?
  expr: String?
  `for`: String?
  
  annotations: Mapping<String, String>
  labels: Mapping<String, String>
}
amends "basealert.pkl"
groups {
  name = "test"
  rules {
    …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dkyanakiev
Comment options

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