Skip to content

Commit

Permalink
docs: remove outdated use of CUE tip version
Browse files Browse the repository at this point in the history
This removes three pages' explicit use of cmd/cue "tip" and demotes them
to latest, which is the version they actually use due to the site's
version aliasing in site.cue.

These were in place to allow the pages to access v0.11 features before
its release, but were missed during the upgrade of the site's latest
version to v0.11.0 in https://cuelang.org/cl/1204275 due to that CL's
documented "grep" being focussed on pre-releases, and not noticing uses
of tip.

Also: given that two of these pages' mention of cue-lang/cue#3265 is no
longer relevant (matchIf/matchN), their upload&script blocks are
translated into code blocks -- which have a slightly more suitable
rendered output form (and are a little faster to compute, given their
lack of persistent context). matchIf/matchNs' preamble is reworded
slightly and aligned, as both pages can have their explicit "cue
version" demonstration removed. Their respective demonstrations that
their functions don't consider helper fields has its field names renamed
from "foo"/"bar" to "aString"/"anInt" to help bring home the point
that's being made.

Preview-Path: /docs/howto/use-the-built-in-function-matchif/
Preview-Path: /docs/howto/use-the-built-in-function-matchn/
Preview-Path: /docs/concept/faq/removing-list-arithmetic-operators-v0.11/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: Ia977bb3976d8a98b0f7d44966f1a555ade43e339
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1206461
Reviewed-by: Paul Jolly <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
jpluscplusm committed Dec 30, 2024
1 parent 0fccd13 commit 4e0ed0e
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ tags: [language]
toc_hide: false
---

{{{with _script_ "en" "HIDDEN: set up access to CUE v0.11 before release"}}}
export PATH=/cues/$CUELANG_CUE_TIP:$PATH
{{{end}}}

This guide answers some questions about a language change that happened in CUE
version 0.11 -- including how to tell if the change affects your CUE, and how
to update any CUE that's affected.
Expand Down Expand Up @@ -51,8 +47,7 @@ that contains list arithmetic operators:

[`cue fix`]({{< relref "/docs/reference/command/cue-help-fix" >}})
will make these changes for you in many cases, but only if you are using `cue`
command version\
`v0.11.0-alpha.1` or later. Here's how to use `cue fix`:
command version `v0.11.0` or later. Here's how to use `cue fix`:

Start with some CUE that requires changes because it uses list arithmetic operators:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ package site
"references: fixed": "ZozhZKFakYVoerJNHsksvK3Vc5KTyh1b129yablmClI="
}
multi_step: {
hash: "N7IREOHQGL944SJBJBAJI35DLV2BKKQ4I2UAG4M4VCMOFFF1E99G===="
scriptHash: "E7I0926EB2FHGKQ4NU1U0297MLTS3N4R2MVPLDVCPPVKFD86DBFG===="
hash: "NNP1L7SP3M6S3MG4AG40LPQ1JHT3A5175P9KADGHL1B5SPKR1NVG===="
scriptHash: "VLNGG98FUABM36HDGI2AH2IQCN9I2OP2RSHEFN8T9SKDP3F1HRP0===="
steps: [{
doc: ""
cmd: "export PATH=/cues/v0.11.1:$PATH"
exitCode: 0
output: ""
}, {
doc: ""
cmd: "cue vet list-arithmetic.cue"
exitCode: 1
Expand Down
68 changes: 31 additions & 37 deletions content/docs/howto/use-the-built-in-function-matchif/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@ authors: [jpluscplusm]
toc_hide: true
---

{{{with _script_ "en" "HIDDEN: access to cue tip"}}}
export PATH=/cues/$CUELANG_CUE_TIP:$PATH
{{{end}}}

This guide demonstrates how to use the
[built-in]({{< relref "docs/reference/glossary#built-in-functions" >}})
function `matchIf` as a field validator.
The function currently requires a
[pre-release]({{< relref "/docs/introduction/installation" >}}#download-an-official-cue-binary)
version of the `cue` command:
function `matchIf`.
It may only be used as a field validator and
can't be called as a function that returns a boolean value.

{{{with script "en" "cue version"}}}
#ellipsis 1
cue version
{{{end}}}

The `matchIf` function must be used as a field validator; it cannot be called
as a function that returns a boolean value. It requires three arguments:
`matchIf` requires three arguments:

1. the *if-value*
2. the *then-value*
Expand All @@ -36,9 +25,10 @@ If the test fails, then the field's value is invalid:
- If the field's value **could not** unify successfully with the *if-value*,
can the field's value also unify successfully with the *else-value*?

<!-- We use upload/script pairs because code blocks can't access non-default
versions of CUE cf. https://cuelang.org/issues/3265 -->
{{{with upload "en" "example"}}}
{{{with code "en" "example"}}}
#location top bottom
! exec cue vet
cmp stderr out
-- example.cue --
package matchIf

Expand All @@ -60,9 +50,18 @@ D: matchIf({x?: int}, _oUnder100, _oOver100)

_oUnder100: {o?: <100}
_oOver100: {o?: >100}
{{{end}}}
{{{with script "en" "basic"}}}
! cue vet
-- out --
B: invalid value 42 (does not satisfy matchIf): invalid value 42 (out of bound >100):
./example.cue:9:4
./example.cue:5:4
./example.cue:9:12
./example.cue:9:17
./example.cue:9:23
D: invalid value {x:"some string",o:99} (does not satisfy matchIf): invalid value 99 (out of bound >100):
./example.cue:17:4
./example.cue:13:4
./example.cue:13:26
./example.cue:20:17
{{{end}}}

## Future enhancements
Expand All @@ -71,28 +70,23 @@ The current release of `matchIf` does not consider hidden fields or definitions
when checking for a match with any of its parameters
(the *if-value*, the *then-value*, or the *else-value*):

{{{with upload "en" "future: helper fields"}}}
{{{with code "en" "future: helper fields"}}}
#location top bottom
exec cue vet .:helperFields # this command succeeds
cmp stdout out
-- helper-fields.cue --
package helperFields

A: {
_foo: "some string"
#bar: 42
baz: 4.2
}
// A validates successfully.
A: matchIf(#A, #A, #A)

#A: {
_foo?: int
#bar?: string
baz!: float
_aString: string
#anInt: int
}
{{{end}}}

{{{with script "en" "future: helper fields"}}}
# This command currently succeeds:
cue vet .:helperFields
A: matchIf(#A, #A, #A) & {
_aString: 42
#anInt: "not an int"
}
-- out --
{{{end}}}

This behaviour *may* change with future CUE releases.
Expand Down
48 changes: 3 additions & 45 deletions content/docs/howto/use-the-built-in-function-matchif/gen_cache.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,9 @@ package site
"use-the-built-in-function-matchif": {
page: {
cache: {
upload: {
example: "18GcN7wtNhQJTfUI0WnoRVJ9Qb5nUziuWTTHGRS7BP0="
"future: helper fields": "JhwaATM40yOrH0LHJhS5K7rJjCwg+HsTg5vByox5mYs="
}
multi_step: {
hash: "USFFA4S5EN2IOEB5COSKRAP7LOC7KNTAU09CKLS7EDUFG6V9OHOG===="
scriptHash: "MJLF7BQ0PCD04D0MGRPCENG1E75OKBQ1J3P1OUDHGIN137JFI2HG===="
steps: [{
doc: ""
cmd: "export PATH=/cues/v0.11.1:$PATH"
exitCode: 0
output: ""
}, {
doc: "#ellipsis 1"
cmd: "cue version"
exitCode: 0
output: """
cue version v0.11.1
...
"""
}, {
doc: ""
cmd: "cue vet"
exitCode: 1
output: """
B: invalid value 42 (does not satisfy matchIf): invalid value 42 (out of bound >100):
./example.cue:9:4
./example.cue:5:4
./example.cue:9:12
./example.cue:9:17
./example.cue:9:23
D: invalid value {x:"some string",o:99} (does not satisfy matchIf): invalid value 99 (out of bound >100):
./example.cue:17:4
./example.cue:13:4
./example.cue:13:26
./example.cue:20:17
"""
}, {
doc: "# This command currently succeeds:"
cmd: "cue vet .:helperFields"
exitCode: 0
output: ""
}]
code: {
example: "uPrPa6jdq9QeZSMltRVk6566QoVCyDTWgyHIry5DXsU="
"future: helper fields": "nBTsEfVPANbdmVStDbgkUOaZ0YDii6W3evJ2oHjlPBA="
}
}
}
Expand Down
Loading

0 comments on commit 4e0ed0e

Please sign in to comment.