### Install Latest CUE from Source Source: https://cuelang.org/docs/introduction/installation Install the latest version of the CUE command from source using Go. Ensure you have Go installed. ```bash $ go install cuelang.org/go/cmd/cue@latest ... ``` -------------------------------- ### Example `module.cue` File Source: https://cuelang.org/docs/reference/modules An example configuration for a `module.cue` file, specifying language version, module path, and dependencies. ```cue language: version: "v0.4.3" module: "foo.example/my/thing@v1" deps: { "foo.example/other/thing@v1": v: "v1.0.2" "foo.example/new/thing@v2": v: "v2.3.4" } ``` -------------------------------- ### Setup OpenSpec Tooling Source: https://cuelang.org/docs/reference/contribution-guidelines Run the setup script from the repository root to create local tooling files for OpenSpec. These files are gitignored. ```bash $ ./_scripts/setup-openspec.sh ``` -------------------------------- ### Install Development Version of CUE from Source Source: https://cuelang.org/docs/introduction/installation Install the development version of CUE from source using Go. This fetches the latest unreleased code. ```bash $ go install cuelang.org/go/cmd/cue@master ... ``` -------------------------------- ### Install CUE using Homebrew Source: https://cuelang.org/docs/introduction/installation Install the CUE command-line tool on macOS and Linux systems using the Homebrew package manager. ```bash $ brew install cue-lang/tap/cue ``` -------------------------------- ### Print CUE Version and Build Information Source: https://cuelang.org/docs/reference/command/cue-help-version Use the 'cue version' command to display the installed CUE version and its build details. This command is useful for verifying your CUE installation and understanding build-specific information. ```bash $ cue help version print the CUE version and build information Usage: cue version [flags] Global Flags: -E, --all-errors print all available errors -i, --ignore proceed in the presence of errors -s, --simplify simplify output ``` -------------------------------- ### YAML Configuration Example Source: https://cuelang.org/docs/concept/how-cue-enables-configuration An example YAML file that can be validated against a CUE schema. Note the data types and values used. ```yaml name: production-www-svc kind: service id: production-www-svc-4fc78 users: min: 1024 max: 1024 maxLoad: "4.2" ``` -------------------------------- ### Example CUE package declaration Source: https://cuelang.org/docs/reference/spec A simple example of a package clause, declaring the package name as 'math'. ```cue package math ``` -------------------------------- ### Open List Example Source: https://cuelang.org/docs/reference/spec Provides an example of how an open list can be represented using the List struct. ```cue open: List & { Elem: 1, Tail: { Elem: 2 } } ``` -------------------------------- ### Sample Configuration JSON Source: https://cuelang.org/docs/howto/generate-cue-from-local-go A sample JSON configuration file used to test the example Go program. ```json { "level": 42, "vals": [ { "name": "cueckoo", "value": "bird" }, { "name": "porcuepine", "value": "mammal" } ] } ``` -------------------------------- ### Verify git-codereview Installation Source: https://cuelang.org/docs/reference/contribution-guidelines After installation, run this command to verify that git-codereview is accessible and functioning correctly. It should display help text. ```bash $ git codereview help ``` -------------------------------- ### Check CUE and Go Versions Source: https://cuelang.org/docs/tutorial/loading-cue-go-api Verify the installed versions of `cue` and `go` to ensure compatibility with the tutorial steps. ```bash $ cue version cue version v0.16.1 ... $ go version go version go1.26.4 linux/amd64 ``` -------------------------------- ### Install CUE on Arch Linux Source: https://cuelang.org/docs/introduction/installation Install CUE on Arch Linux using the Pacman package manager from the official 'extra' repository. ```bash $ pacman -S extra/cue ``` -------------------------------- ### Example JSON input file Source: https://cuelang.org/docs/concept/how-cue-works-with-json A sample JSON file representing a configuration, used for validation against a CUE schema. ```json { "a": 1, "b": "2", "c": "three", "d": 4.4 } ``` -------------------------------- ### Start a Local In-Memory OCI Registry Source: https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry Use this command to start a simple, in-memory OCI server for testing. If the port is in use, select a different one and update subsequent commands. ```bash $ cue mod registry localhost:5001 ``` -------------------------------- ### Basic Registry Configuration Examples Source: https://cuelang.org/docs/reference/command/cue-help-registryconfig Set the CUE_REGISTRY environment variable to the hostname of the registry. Examples include a simple hostname, a hostname with a port, and a hostname with a port using an IP address. ```bash CUE_REGISTRY=myregistry.example ``` ```bash CUE_REGISTRY=localhost:5000 ``` ```bash CUE_REGISTRY='[::1]:5000' ``` -------------------------------- ### Command-line JSON Schema Validation Examples Source: https://cuelang.org/docs/concept/how-cue-works-with-json-schema Demonstrates running the Go program to validate JSON data against a schema. Shows successful validation output and an example of a validation error. ```bash $ go run . schema.json good.json { name: "Dorothy Cartwright" address: "Ripon, North Yorkshire" } ``` ```bash $ go run . schema.json bad.json name: conflicting values ["Charlie","Cartwright"] and strings.MinRunes(1) (mismatched types list and string): bad.json:2:13 schema.json:13:14 exit status 1 ``` -------------------------------- ### Check build prerequisites Source: https://cuelang.org/docs/howto/build-cue-api-java-jar Verify that Java, Maven, and Git executables are installed and meet the minimum version requirements. ```bash $ javac --version javac 22.0.2 $ mvn --version ... $ git --version git version 2.47.3 ``` -------------------------------- ### CUE Input Example Source: https://cuelang.org/docs/concept/using-the-cue-export-command/evaluation A basic CUE file defining a package and a data field. ```cue package one data: true ``` -------------------------------- ### Start a Local CUE Module Registry Source: https://cuelang.org/docs/reference/command/cue-help-mod-registry Starts an OCI-compliant server that stores CUE module contents in memory. This is useful for testing purposes. Point the CUE_REGISTRY environment variable to the server's address to publish modules. ```bash $ cue help mod registry This command starts an OCI-compliant server that stores all its contents in memory. It can serve as a scratch CUE modules registry for use in testing. For example, start a local registry with: cue mod registry localhost:8080 and point CUE_REGISTRY to it to publish a module version: CUE_REGISTRY=localhost:8080 cue mod publish v0.0.1 Note: this command might be removed or changed significantly in the future. Usage: cue mod registry [listen-address] [flags] Global Flags: -E, --all-errors print all available errors -i, --ignore proceed in the presence of errors -s, --simplify simplify output ``` -------------------------------- ### Unification and Disjunction Examples Source: https://cuelang.org/docs/references/spec Illustrates the results of applying unification and disjunction to different CUE expressions. ```cue Expression Result ({a:1} | {b:2}) & {c:3} {a:1, c:3} | {b:2, c:3} (int | string) & "foo" "foo" ("a" | "b") & "c" _|_ ``` -------------------------------- ### Create Tutorial Directory and Files Source: https://cuelang.org/docs/tutorial/validating-simple-yaml-files Set up the necessary directory and initial files for the tutorial. This includes creating a directory and sample YAML and CUE files. ```bash $ mkdir validating-yaml-with-cue $ cd validating-yaml-with-cue ``` -------------------------------- ### Get Help for a Specific CUE Command Source: https://cuelang.org/docs/reference/command/cue-help To understand the usage and options for a particular CUE command, append the command name to 'cue help'. For example, 'cue help eval' provides details on the 'eval' command. ```bash cue help [command] ``` -------------------------------- ### Install OpenSpec CLI Source: https://cuelang.org/docs/reference/contribution-guidelines Install the OpenSpec CLI tool globally using npm. Ensure Node.js version 20.19.0 or higher is installed. ```bash $ npm install -g @fission-ai/openspec@latest ``` -------------------------------- ### Test Go Program with Sample Config Source: https://cuelang.org/docs/howto/generate-cue-from-local-go Run the Go program and pipe the sample configuration into its standard input to verify it accepts the data. ```bash $ cat config.json | go run . Config level: 42. Val count: 2. First val name: "cueckoo". ``` -------------------------------- ### Operator Examples Source: https://cuelang.org/docs/reference/spec Illustrates the application of various CUE operators, including arithmetic, logical, unification, and disjunction. ```cue +x ``` ```cue 23 + 3*x[i] ``` ```cue x <= f() ``` ```cue f() || g() ``` ```cue x == y+1 && y == z-1 ``` ```cue 2 | int ``` ```cue { a: 1 } & { b: 2 } ``` -------------------------------- ### Example Text File Content Source: https://cuelang.org/docs/howto/embed-files-in-cue-evaluation This is an example of a text file that can be embedded. ```text # How to use this project ## Installation Fetch the latest release from the official site, and unpack it in your home directory. Next ... ``` -------------------------------- ### Initialize a CUE module Source: https://cuelang.org/docs/reference/command/cue-help-mod-init Use this command to initialize a new CUE module in the current directory. If no module name is provided, `cue.example` is used. A legacy `cue.mod` file will be moved to the new subdirectory. ```bash $ cue help mod init ``` -------------------------------- ### Bounds Examples Source: https://cuelang.org/docs/reference/spec Demonstrates the use of bounds for representing infinite disjunctions of concrete values through comparisons. ```cue 2 & >=2 & <=5 // 2, where 2 is either an int or float. 2.5 & >=1 & <=5 // 2.5 2 & >=1.0 & <3.0 // 2.0 2 & >1 & <3.0 // 2.0 2.5 & int & >1 & <5 // _|_ 2.5 & float & >1 & <5 // 2.5 int & 2 & >1.0 & <3.0 // _|_ 2.5 & >=(int & 1) & <5 // _|_ >=0 & <=7 & >=3 & <=10 // >=3 & <=7 !=null & 1 // 1 ==[1, 2] & [1] // _|_ !=[1, 2] & [1] // [1] ``` -------------------------------- ### Initialize CUE and Go Modules Source: https://cuelang.org/docs/howto/place-data-go-api Initialize CUE and Go modules for a new project. ```bash $ cue mod init cue.example $ go mod init go.example ``` -------------------------------- ### Example JSON File Content Source: https://cuelang.org/docs/howto/embed-files-in-cue-evaluation This is an example of a JSON file that can be embedded. ```json { "aField": "a value" } ``` ```json { "aList": [ 1, 2, 3 ] } ``` ```json { "anObject": { "foo": "a", "bar": "b", "baz": "c" } } ``` -------------------------------- ### CUE Schema Example Source: https://cuelang.org/docs/introduction Example of a CUE schema defining the structure for any municipality. ```cue municipality: { name: string pop: int capital: bool } ``` -------------------------------- ### YAML Data Example Source: https://cuelang.org/docs/concept/how-cue-enables-data-validation Example of a YAML data file used for validation. ```yaml name: Charlie Cartwright type: cat diet: chicken ``` -------------------------------- ### JSON Data Example Source: https://cuelang.org/docs/concept/how-cue-enables-data-validation Example of JSON data files used for validation. ```json { "name": "Alex Atkinson", "type": "dog", "height": 55, "diet": "kibble" } ``` ```json { "name": "Bryn Brown", "type": "goldfish", "height": "2", "diet": "flakes" } ``` -------------------------------- ### CUE Input Example Source: https://cuelang.org/docs/concept/how-cue-works-with-toml A sample CUE file used as input for CUE processing, defining data and relationships. ```cue b: _ g: _ h: "six" b: d: i: g + b.d.e ``` -------------------------------- ### Qualified Identifier Example Source: https://cuelang.org/docs/reference/spec Example of using a qualified identifier to reference a function from the 'math' package. ```cue math.Sin // denotes the Sin function in package math ``` -------------------------------- ### Create Project Directory Source: https://cuelang.org/docs/tutorial/get-started-cue-java Create a new directory for CUE Java API tutorials and navigate into it. This provides a clean workspace for the tutorial examples. ```bash $ mkdir -p cue-java-api-tutorials $ cd cue-java-api-tutorials ``` -------------------------------- ### CUE Data Example Source: https://cuelang.org/docs/introduction Example of a JSON object in CUE syntax representing data about Moscow. ```cue moscow: { name: "Moscow" pop: 11.92M capital: true } ``` -------------------------------- ### Example birthdays.json Data Source: https://cuelang.org/docs/howto/place-data-files-different-locations-file-embedding This is an example JSON file containing birthday data for different individuals. ```json { "alex": "1984-02-29", "jamie": "2000-01-01", "charlie": "1950-06-26" } ``` -------------------------------- ### Initialize a new CUE module Source: https://cuelang.org/docs/tutorial/publishing-modules-to-the-central-registry Create a new directory for your module, initialize it as a Git repository, and set up the CUE module configuration. Remember to replace 'cueckoo' with your GitHub username. ```bash $ mkdir ../frostyapp $ cd ../frostyapp $ git init -q $ cue mod init --source=git github.com/cueckoo/frostyapp@v0 ``` -------------------------------- ### Example addresses.yml Data Source: https://cuelang.org/docs/howto/place-data-files-different-locations-file-embedding This is an example YAML file containing address data for different individuals. ```yaml jamie: - 1 Main Street - Townsville - West Fooshire alex: - 42 The Parade - Village-on-the-Wold - Countyshire ``` -------------------------------- ### Initialize a new CUE module Source: https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry Create a new directory, initialize a Git repository, and set up a new CUE module with a specified source. ```bash $ mkdir ../frostyapp $ cd ../frostyapp $ git init -q $ cue mod init --source=git glacial-tech.example/frostyapp@v0 ``` -------------------------------- ### Protobuf Definition File Source: https://cuelang.org/docs/integration/protobuf This is a sample Protobuf file (`basic.proto`) used for demonstrating the conversion to CUE. It includes basic message structure and a field with a CUE validation constraint in its options. ```protobuf syntax = "proto3"; // Package basic is rather basic. package cuelang.examples.basic; import "cue/cue.proto"; option go_package = "cuelang.org/encoding/protobuf/examples/basic"; // This is my type. message MyType { string string_value = 1; // Some string value // A method must start with a capital letter. repeated string method = 2 [(cue.val) = '[...=~"^[A-Z]"']; } ``` -------------------------------- ### Test All Packages Source: https://cuelang.org/docs/reference/contribution-guidelines Run 'go test ./...' from the CUE repository root to test all packages. This is recommended before submitting a change. ```bash $ cd $CUEDIR $ go test ./... ``` -------------------------------- ### Install git-codereview Command Source: https://cuelang.org/docs/reference/contribution-guidelines Installs the git-codereview command-line tool, which simplifies submitting changes to Gerrit. Ensure the tool is in your PATH. ```bash $ go install golang.org/x/review/git-codereview@master ``` -------------------------------- ### Create and Initialize Schema Module Directory Source: https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry Set up a new directory for the schema module and initialize it as a Git repository and a CUE module. This prepares the environment for defining and publishing CUE code. ```bash $ mkdir frostyconfig $ cd frostyconfig $ git init -q $ cue mod init --source=git glacial-tech.example/frostyconfig@v0 ``` -------------------------------- ### CUE Data and Schema Mix Example Source: https://cuelang.org/docs/introduction Example demonstrating CUE's ability to mix data and schema definitions. ```cue largeCapital: { name: string pop: >5M capital: true } ``` -------------------------------- ### Display CUE Help Information Source: https://cuelang.org/docs/reference/command/cue-help Run 'cue help' to display a summary of CUE's capabilities and a list of available commands. Use 'cue help [command]' for detailed information on a specific command. ```bash $ cue help ``` -------------------------------- ### Example CUE_REGISTRY Configuration Source: https://cuelang.org/docs/reference/modules Illustrates a CUE_REGISTRY configuration with multiple registries. It shows how a default registry is used for most modules, while a specific prefix directs modules to a different registry with a custom repository structure. ```text CUE_REGISTRY=public-registry.example,github.com/acmecorp=registry.acme.example:6000/modules ``` -------------------------------- ### Load and Display CUE Data in Go Source: https://cuelang.org/docs/concept/how-cue-works-with-go Use `load.Instances` to load CUE packages and `cuecontext.BuildInstance` to build CUE values. The default formatter renders CUE values sensibly. ```cue package example l: [1, 2, 3] v: "hello" message: (v): "world!" ``` ```go package main import ( "fmt" "cuelang.org/go/cue/cuecontext" "cuelang.org/go/cue/load" ) func main() { ctx := cuecontext.New() insts := load.Instances([]string{"."}, nil) v := ctx.BuildInstance(insts[0]) fmt.Printf("%v\n", v) } ``` ```bash $ go get cuelang.org/go@v0.16.1 ... $ go mod tidy ... ``` ```bash $ go run . { l: [1, 2, 3] v: "hello" message: { hello: "world!" } } ``` -------------------------------- ### Example CUE input file Source: https://cuelang.org/docs/concept/how-cue-works-with-json A sample CUE file with simple key-value pairs, which can be processed alongside JSON and YAML. ```cue e: 5 f: "6" ``` -------------------------------- ### Example Docker Compose File Source: https://cuelang.org/docs/tutorial/cfgmgmtcamp-2025 This is an example of a docker-compose.yaml file used for testing services. It defines services, their images, ports, and volumes. ```yaml service: frontend: image: docker.io/library/nginx:latest ports: - "80:80" volume: - ./html:/usr/share/nginx/html - ./config/nginx.conf:/etc/nginx/nginx.conf:ro db: image: docker.ru/library/postgres:17.0 ``` -------------------------------- ### CUE Export Examples with Different Tags Source: https://cuelang.org/docs/howto/conditionally-include-cue-files-using-build-attributes Demonstrates how `cue export` output varies based on the presence or absence of build tags. ```bash $ cue export { "data from bar.cue": true, "data from baz.cue": true } $ cue export -t foo { "data from bar.cue": true, "data from baz.cue": true, "data from foo.cue": true, "data from qux.cue": true } $ cue export -t bar { "data from baz.cue": true, "data from qux.cue": true } $ cue export -t foo -t bar { "data from baz.cue": true, "data from foo.cue": true } ``` -------------------------------- ### Load and Build CUE Package in Go Source: https://cuelang.org/docs/tutorial/using-modules-with-go-api This Go program demonstrates loading a CUE package from the current directory using the CUE Go API. It initializes a CUE context, sets up a module registry client, loads instances, builds a CUE value, and looks up a specific field. ```go package main import ( "fmt" "log" "cuelang.org/go/cue" "cuelang.org/go/cue/cuecontext" "cuelang.org/go/cue/load" "cuelang.org/go/mod/modconfig" ) func main() { ctx := cuecontext.New() // Create a registry client. Passing a nil config // will give us client that behaves like the cue command. reg, err := modconfig.NewRegistry(nil) if err != nil { log.Fatal(err) } // Load the package from the current directory. // We don't need to specify a Config in this example. insts := load.Instances([]string{"."}, &load.Config{ Registry: reg, }) // The current directory just has one file without any build tags, // and that file belongs to the example package, so we get a single // instance as a result. v := ctx.BuildInstance(insts[0]) if err := v.Err(); err != nil { log.Fatal(err) } // Lookup the 'config' field and print it out config := v.LookupPath(cue.ParsePath("config")) fmt.Println(config) } ``` -------------------------------- ### Start an In-Memory Registry Source: https://cuelang.org/docs/howto/mirror-modules-between-registries Starts a local, in-memory registry listening on a specified address. This registry is ephemeral and its contents are lost when it stops. ```bash $ cue mod registry 127.0.0.1:55443 ``` -------------------------------- ### CUE Configuration with Templates and Defaults Source: https://cuelang.org/docs/concept/how-cue-enables-configuration Demonstrates CUE features like templates and defaults for concise configuration. The `job` struct contains unique details, while a template unifies common constraints and defaults for `command` and `replicas`. ```cue job: { nginx: replicas: 2 manager: command: "monit -I" policyd: _ boltdb: replicas: 3 postgres: replicas: 5 } // This template's constraints are unified with // each member of the job struct. job: [Name=_]: { name: Name // command can be set, but has a default. command: string | *"exec \(Name)" // replicas can be set, but defaults to 1. replicas: uint | *1 } // Databases are important, so increase the replica // minimum for members of the job struct whose keys // match #DB. job: [#DB]: replicas: >=3 #DB: "postgres" | "mysql" | =~"db$" ``` -------------------------------- ### Disjunction and Unification Examples Source: https://cuelang.org/docs/reference/spec Illustrates the practical application of disjunction and unification with concrete CUE expressions and their results. Shows how types and values interact. ```cue ({a:1} | {b:2}) & {c:3} {a:1, c:3} | {b:2, c:3} ``` ```cue (int | string) & "foo" "foo" ``` ```cue ("a" | "b") & "c" _|_ ``` -------------------------------- ### Good JSON Data Example Source: https://cuelang.org/docs/howto/validate-json-using-go-api Example of a JSON object that conforms to the defined CUE schema. It includes a 'name' as a string and 'age' as an integer. ```json { "name": "Charlie Cartwright", "age": 80 } ``` -------------------------------- ### Start CUE Module Registry Source: https://cuelang.org/docs/tutorial/cfgmgmtcamp-2025 Starts a local CUE module registry on the specified address. This is used for testing module publishing and fetching. ```bash $ cue mod registry 127.0.0.1:55443 & ``` -------------------------------- ### Example YAML Data File Source: https://cuelang.org/docs/howto/validate-data-files-using-file-embedding This is an example YAML file that will be embedded and validated. It contains a value for 'X' that violates the constraint defined in the CUE schema. ```yaml X: 11 O: 222 ``` -------------------------------- ### Mirroring All Versions of Modules Source: https://cuelang.org/docs/reference/command/cue-help-mod-mirror Copies all available versions of the specified modules from the default source registry to 'my.registry.example'. ```bash $ cue mod mirror --to my.registry.example --all-versions foo.com/m1 bar.org ``` -------------------------------- ### Initialize a new CUE module Source: https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry Use this command to create a new directory, initialize a git repository, and set up a new CUE module. The `--source=git` flag indicates the module will be sourced from a Git repository. ```bash $ mkdir ../frostytemplate $ cd ../frostytemplate $ git init -q $ cue mod init --source=git glacial-tech.example/frostytemplate@v0 ``` -------------------------------- ### Example JSON Data File Source: https://cuelang.org/docs/howto/validate-data-files-using-file-embedding This is an example JSON file that will be embedded and validated against the CUE schemas. It contains values that will cause type and value validation errors. ```json { "X": 1, "O": 2.2 } ``` -------------------------------- ### Example OpenAPI Output Source: https://cuelang.org/docs/concept/how-cue-works-with-openapi This is an example of the OpenAPI document generated from a CUE schema. It shows the basic structure including openapi version, info, paths, and components. ```json { "openapi": "3.0.0", "info": { "title": "A schema for the pet API.", "version": "v1.2.3" }, "paths": {}, "components": { "schemas": { "Kind": { ... } ``` -------------------------------- ### Example: Include Schema Under a Path Source: https://cuelang.org/docs/reference/command/cue-help-flags Shows how to include a schema definition under the 'myschema' field in the CUE configuration using path notation. ```bash $ cue eval -l myschema: schema: foo.json ``` -------------------------------- ### Comparison Examples Source: https://cuelang.org/docs/reference/spec Provides examples of CUE comparison operators, including numeric, equality, and regular expression matching. Note that struct comparison with `==` results in bottom. ```cue 3 < 4 // true ``` ```cue 3 < 4.0 // true ``` ```cue null == 2 // false ``` ```cue null != {} // true ``` ```cue {} == {} // _|_: structs are not comparable against structs ``` ```cue "Wild cats" =~ "cat" // true ``` ```cue "Wild cats" !~ "dog" // true ``` -------------------------------- ### Example Go Program Source: https://cuelang.org/docs/howto/generate-cue-from-local-go This Go program defines `Config` and `Val` types and loads a JSON-encoded configuration from stdin. Use your own Go code and types for generation. ```go package main import ( "encoding/json" "fmt" "log" "os" ) type Config struct { Vals []Val `json:"vals"` Level int `json:"level"` } type Val struct { Name string `json:"name"` Value string `json:"value"` } func main() { var cfg Config dec := json.NewDecoder(os.Stdin) if err := dec.Decode(&cfg); err != nil { log.Fatal(err) } fmt.Printf("Config level: %d.\n", cfg.Level) fmt.Printf("Val count: %d.\n", len(cfg.Vals)) if len(cfg.Vals) > 0 { fmt.Printf("First val name: %q.\n", cfg.Vals[0].Name) } } ``` -------------------------------- ### Good Commit Message Example Source: https://cuelang.org/docs/reference/contribution-guidelines An example of a well-formatted commit message following CUE conventions. It includes a concise summary line, detailed explanation, and issue referencing. ```text cue/ast/astutil: fix resolution bugs This fixes several bugs and documentation bugs in identifier resolution. 1. Resolution in comprehensions would resolve identifiers to themselves. 2. Label aliases now no longer bind to references outside the scope of the field. The compiler would catch this invalid bind and report an error, but it is better not to bind in the first place. 3. Remove some more mentions of Template labels. 4. Documentation for comprehensions was incorrect (Scope and Node were reversed). 5. Aliases X in `X=[string]: foo` should only be visible in foo. Fixes #946 ``` -------------------------------- ### CUE code for YAML validation examples Source: https://cuelang.org/docs/howto/use-encoding-yaml-validate-encoding-yaml-validatepartial-as-field-validators This CUE code defines YAML data and schemas to demonstrate the usage of `encoding/yaml.Validate` and `encoding/yaml.ValidatePartial`. It includes examples that are expected to fail validation. ```cue package example import "encoding/yaml" data: """ a: 1 b: "two" "" // Validate requires that all non-optional fields in a schema are present in // data, and that data adheres to schema constraints. data: yaml.Validate(_outOfBoundsSchema) data: yaml.Validate(_missingFieldSchema) // ValidatePartial requires only that data adheres to schema constraints. data: yaml.ValidatePartial(_outOfBoundsSchema) data: yaml.ValidatePartial(_missingFieldSchema) _outOfBoundsSchema: { a!: >99 // validation failure for both functions b!: string } _missingFieldSchema: { a!: int b!: string c!: bool // validation failure for yaml.Validate only } ``` -------------------------------- ### Import Protobuf File using `cue import` Source: https://cuelang.org/docs/concept/how-cue-works-with-protocol-buffers Use the `cue import` command to convert a Protobuf file (`basic.proto`) into a CUE file. Successful conversion typically results in no output. ```bash $ cue import basic.proto ``` -------------------------------- ### Check Prerequisites Source: https://cuelang.org/docs/tutorial/get-started-cue-java Verify that the Java Development Kit (JDK) is installed and accessible, the libcue shared library is found, and the CUE Java JAR files are correctly located in the CLASSPATH. ```bash $ javac --version javac 22.0.2 $ ls $LD_LIBRARY_PATH | grep libcue.so || echo 'fail!' libcue.so $ ls $CLASSPATH | grep /CUE.*jar$ || echo 'fail!' /usr/local/share/java/CUE.jar ``` -------------------------------- ### cue help get Command Usage Source: https://cuelang.org/docs/reference/command/cue-help-get Displays the general usage and available commands for 'cue get'. Use this to understand the basic structure and subcommands like 'crd' and 'go'. ```bash $ cue help get Get downloads packages or modules for non-CUE languages to include them in the module's pkg directory. Get requires an additional language field to determine for which language definitions should be fetched. Definitions are extracted from the source of the respective language and stored. The specifics on how dependencies are fetched and converted vary per language and are documented in the respective subcommands. For information on native CUE modules: cue help modules Usage: cue get [packages] [flags] cue get [command] Available Commands: crd convert Kubernetes CRDs to packages in the current module go add Go dependencies to the current module Global Flags: -E, --all-errors print all available errors -i, --ignore proceed in the presence of errors -s, --simplify simplify output Use "cue get [command] --help" for more information about a command. ``` -------------------------------- ### Initialize CUE Module Source: https://cuelang.org/docs/howto/generate-cue-from-local-go Create a CUE module to hold the generated CUE code. This is necessary if you don't already have one. ```bash $ cue mod init an.example ``` -------------------------------- ### Bad JSON Data Example Source: https://cuelang.org/docs/howto/validate-json-using-go-api Example of a JSON object that violates the defined CUE schema. 'name' is an array of strings instead of a single string, and 'age' is a string instead of an integer. ```json { "name": [ "Moby", "Dick" ], "age": "173" } ``` -------------------------------- ### Test Single Package Source: https://cuelang.org/docs/reference/contribution-guidelines Navigate to the 'cue' directory and run 'go test' to compile and test only the current package. This is faster than testing all packages. ```bash $ cd $CUEDIR/cue $ [make changes...] $ go test ``` -------------------------------- ### Another example CUE input file Source: https://cuelang.org/docs/concept/how-cue-works-with-json A CUE file containing a string and an arithmetic expression, demonstrating CUE's processing capabilities. ```cue g: "seven" h: 4.4 * 2 ``` -------------------------------- ### Run the Go program Source: https://cuelang.org/docs/tutorial/using-modules-with-go-api This snippet shows how to run the Go program that uses CUE modules. ```go go run . ``` -------------------------------- ### Declare CUE Schema Example Source: https://cuelang.org/docs/howto/walk-schemas-using-go-api Define a CUE schema including struct types, optional fields, and concrete data. This example includes definitions for #Person and #Address, along with instance data. ```cue package example #Person: name!: string age?: int & >=0 #Address: line1!: string line2?: string line3?: string country?: string aPerson: #Person & { name: "John Adams" } anAddress: #Address & { line1: "1600 Pennsylvania Ave NW" line2: "Washington, DC 20500" country: "United States of America" } someData: aValue: 42 _aHiddenField: aValue: 139 ``` -------------------------------- ### Check Go and cgo version Source: https://cuelang.org/docs/howto/build-libcue-shared-library Verify that Go version 1.22 or later is installed and that cgo is enabled by checking the go version and the CGO_ENABLED environment variable. ```bash $ go version go version go1.26.4 linux/amd64 $ go env CGO_ENABLED 1 ``` -------------------------------- ### Default Value Resolution Examples Source: https://cuelang.org/docs/reference/spec Demonstrates the final resolved values of CUE expressions, particularly focusing on how default values affect the outcome. These examples showcase practical applications of default value rules. ```cue Expression Resolves to "tcp" | "udp" "tcp" | "udp" *"tcp" | "udp" "tcp" float | *1 1 *string | 1.0 string (*1|2) + (2|*3) 4 (*1|2|3) | (1|*2|3) 1|2 (*1|2|3) & (1|*2|3) 1|2|3 // default is _|_ (* >=5 | int) & (* <=5 | int) 5 (*"tcp"|"udp") & ("udp"|"tcp") "tcp" (*"tcp"|"udp") & ("udp"|"tcp") "tcp" (*"tcp"|"udp") & "tcp" "tcp" (*"tcp"|"udp") & (*"udp"|"tcp") "tcp" | "udp" // default is _|_ (*true | false) & bool true (*true | false) & (true | false) true {a: 1} | {b: 1} {a: 1} | {b: 1} {a: 1} | *{b: 1} {b:1} *{a: 1} | *{b: 1} {a: 1} | {b: 1} ({a: 1} | {b: 1}) & {a:1} {a:1} | {a: 1, b: 1} ({a:1}|*{b:1}) & ({a:1}|*{b:1}) {b:1} ``` -------------------------------- ### Initialize CUE Module Source: https://cuelang.org/docs/tutorial/using-modules-with-go-api Initialize a new CUE module in an empty directory. The module name is arbitrary as it's not intended for publication. ```bash $ cue mod init an.example/config@v0 ``` -------------------------------- ### Example: Base Path Values on Contextual Data Source: https://cuelang.org/docs/reference/command/cue-help-flags Illustrates using the --with-context flag to base CUE path values on contextual information like the filename and data kind from a YAML file. ```bash $ cue eval --with-context -l 'path.Base(filename)' -l data.kind foo.yaml ``` -------------------------------- ### Example Data for Integer String Validation Source: https://cuelang.org/docs/howto/constrain-string-as-valid-integer This YAML data provides example values for s1 and s2. s1 is a valid integer string, while s2 is a floating-point number string, which will cause validation to fail. ```yaml # s1 is a valid integer s1: "137" # s2 is not a valid integer s2: "42.7" ``` -------------------------------- ### Example Terminal Output for JSON Schema Generation Source: https://cuelang.org/docs/concept/how-cue-works-with-json-schema This is an example of the terminal output when running the Go program to generate JSON Schema from a CUE file. It shows a partial representation of the generated schema for a '#Team' definition. ```bash $ go run ./gen generate_schema.cue '#Team' { "Lbrace": {}, "Elts": [ { "Label": { "NamePos": {}, "Name": "$schema", "Scope": null, "Node": null }, ... } ``` -------------------------------- ### Displaying Help for 'cue login' Source: https://cuelang.org/docs/reference/command/cue-help-login Shows the help text for the 'cue login' command, detailing its usage, flags, and global options. ```bash $ cue help login ```