github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/doc/tutorial/basics/6_expressions/55_conditional.txt (about)

     1  cue eval conditional.cue
     2  cmp stdout expect-stdout-cue
     3  
     4  -- frontmatter.toml --
     5  title = "Conditional Fields"
     6  description = ""
     7  
     8  -- text.md --
     9  Field comprehensions can also be used to
    10  add a single field conditionally.
    11  
    12  Converting the resulting configuration to JSON results in an error
    13  as `justification` is required yet no concrete value is given.
    14  
    15  -- conditional.cue --
    16  price: number
    17  
    18  // Require a justification if price is too high
    19  if price > 100 {
    20      justification: string
    21  }
    22  
    23  price: 200
    24  
    25  -- expect-stdout-cue --
    26  price:         200
    27  justification: string