Code Monkey home page Code Monkey logo

cue-notes's Introduction

Cue

Useful Commands

  • Print one object at a "deep" level with values set at every level above

    cue eval ./stages/prd/regions/... -e envoy
    
  • Print object at a SPECIFIC level

    cue eval ./stages/prd/regions/envoy.cue -e envoy
    
  • Check yaml against cue

    cue vet ranges.yaml check.cue
    
  • Vet Cue (give it the deepest level. It wont traverse down itself)

    cue vet -c --strict ./stages/prd/regions/...
    
  • Format

    cue fmt ./...
    
  • Render YAML

package main

import (
	"encoding/yaml"
	"tool/cli"
)

command: dump: {
	task: print: cli.Print & {
		text: yaml.Marshal(_rendered)
	}
}
cue cmd dump ./main/...

Debugging

  • incomplete value string: - you are missing a concrete value somewhere. yaml.Marshal is EXTREMELY finicky. You will want to pull whatever out of yaml.Marshal() into a thing that you can run via cue eval. Look for places where you don't have concrete values. Those ALL need fixed.

Pattern

  • We create a debug/ directory at the same level as the package we are trying to debug or "simulate". Then, we symlink all .cue files that DON'T include yaml.Marshal(..).
mkdir debug && cd debug
ln -snf ../main/debug.cue .
ln -snf ../main/modify.cue .

Then, we can debug Cue via the following

cue eval ./debug/... -e '_debug'

And, we can still render/test marshalling the same cue to yaml with

cue cmd dump ./main/...

Getting Started

  1. Define the interface you want users to use FIRST.
  2. Define the input schema --- with constraints and defaults
    • Don't try to rely directly on the output schema for the input schema too
    • I ran into a lot of pain doing this
  3. Define the output schema --- with contstraints and defaults. Use defaults generously --- you want (or need) to produce
  4. Define transformation "functions" via the function pattern
  • Mental model

    • Think merging multi-level (or layered) value maps (JSON objects) without overrides
    • "Objects" think "Go Structs"
    • Schemas can have constraints and default values
    • Packages are like Go package i.e., keep domains, etc. packaged
    • Types and values are one and the same (for loops, etc)
    • Order of evaluation does not matter
    • In global packages, set defaults, DON'T set concrete values (in most cases)
      • No such thing as "overwriting" at a deeper level
    • You take the type and constraints, but cant overwrite once a value becomes concrete
    • Types - https://cuetorials.com/overview/types-and-values/
  • Project Structure

    • https://alpha.cuelang.org/docs/concept/modules-packages-instances/#instances
    • Within a module, all .cue files with the same package name are part of the same package.
    • A package is evaluated within the context of a certain directory.
    • Within this context, only the files belonging to that package in that directory and its ancestor directories within the module are combined.
    • We call that an instance of a package.
      • "fully-compiled, concrete data-structure of the package in this 'instance'" when you reference this
    • module root: schema
      • all policy
    • medial directories: policy
      • some policy
    • leaf directories: data
      • all data

Links / References

Understanding Fundamentals

Patterns

cue eval ./oneOf/...
cue eval ./debug/... -e _debug
cue eval ./bottom/... -e output

set:                  "a"
notSet:               "im explicitly setting here"
notSetButWithDefault: "default"
cue cmd "read_file" ./read_file

cue-notes's People

Contributors

mccurdyc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.