Skip to content

abcue/coding-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Coding Style

Self described in coding-style.cue

Patterns

Try out in https://cuelang.org/play/ to understand how it works.

[N=_]

application: [N=_]: {
  name: N
}

The constraint above defines a struct with field name equals the key.

  • _ is the top value, basically it means no constraint.
  • Nis an alias which we may use as a reference to the value.
  • [] is pattern, it define constraints that apply to a collection of fields.

(N)

Expression

let N="myapp"
application: (N): _

results in

application: "myapp": _

(N) is a dynamic field whose label is determined by an expression.

if X != _|_ {}

Expression

deploy: chart: _
if deploy.chart.build != _|_ {
  application: build: deploy.chart.build
}

results in

deploy: {
 chart: _
}

#D & {...} vs { #D }

#App: {
  name: string
}

app: #App & {
  name: "myapp"
}

appWithVersion: {
  #App
  version: "1.0.0"
}

// appWithVersion.version: field not allowed:
// appWithVersion: #App & {
//  #App
//  version: "1.0.0"
// }
  • # defines a definition that closes a struct to forbid unknown fields.
  • & is a unification of #App with a concrete value for the field name.
  • { A } is a struct contains an embedded value bypassing the definition restrict to add field version.

*d | (d & {k: v})

Override default conditionally

*r | (r & {expr: strings.Replace(r.expr, T, "\(#var.alerts.threshold[r.alert][strings.ToLower(r.labels.severity)])", -1)})
  • Default to r when threshold not defined, i.e #var.alerts.threshold[r.alert][strings.ToLower(r.labels.severity)] evals to _|_

Appendix

Documents

CUE in upstream

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages