Skip to content

Commit

Permalink
preprocessor: copy the command that was executed for code block
Browse files Browse the repository at this point in the history
When we have a terminal tab in a code block, we currently copy the
entire contents of the pane, which includes the '$' prefix, the
command... and its output.

This CL fixes that to only copy the command that was executed.

This is a rather hacky change, very much in-line with the hacky code
that exists in code_node.go.

For review focus on the code and test changes in internal/.

Then review the language guide Preview-Path URL to confirm that a
non-terminal output still works, and the list.Sort howto to verify that
a terminal-based output does indeed only copy the command.

Fixes cue-lang/cue#2669

Preview-Path: /docs/language-guide/data/json-superset
Preview-Path: /docs/howto/use-list-sort-to-sort-lists
Preprocessor-No-Write-Cache: true
Signed-off-by: Paul Jolly <[email protected]>
Change-Id: Ia3eb84eaab2cd66c21ad50ee600c70b14714b00a
Dispatch-Trailer: {"type":"trybot","CL":1177017,"patchset":2,"ref":"refs/changes/17/1177017/2","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Feb 19, 2024
1 parent d9e26e6 commit 8e21d16
Show file tree
Hide file tree
Showing 129 changed files with 451 additions and 431 deletions.
18 changes: 9 additions & 9 deletions hugo/content/en/docs/concept/alias-and-reference-scopes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ looks like <code>expected.yaml</code>, but instead I end up with these
{{< /quote >}}

{{< code-tabs >}}
{{< code-tab name="problem1.cue" language="cue" area="top-left" >}}
{{< code-tab name="problem1.cue" language="cue" area="top-left" >}}
#Metadata: {
name: string
namespace: string
Expand Down Expand Up @@ -48,7 +48,7 @@ config: #Config & {
}
}
{{< /code-tab >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
config:
metadata:
name: test
Expand All @@ -62,7 +62,7 @@ config:
name: test
namespace: dev
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCBwcm9ibGVtMS5jdWUgLS1vdXQgeWFtbA==" >}}
$ cue export problem1.cue --out yaml
config.serviceA.metadata.name: incomplete value string:
./problem1.cue:2:13
Expand Down Expand Up @@ -126,7 +126,7 @@ incomplete values! Can you tell me why?
{{< /quote >}}

{{< code-tabs >}}
{{< code-tab name="problem2.cue" language="cue" area="top-left" >}}
{{< code-tab name="problem2.cue" language="cue" area="top-left" >}}
#Metadata: {
name: string
namespace: string
Expand Down Expand Up @@ -155,7 +155,7 @@ config: #Config & {
}
}
{{< /code-tab >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
config:
metadata:
name: test
Expand All @@ -169,7 +169,7 @@ config:
name: test
namespace: dev
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCBwcm9ibGVtMi5jdWUgLS1vdXQgeWFtbA==" >}}
$ cue export problem2.cue --out yaml
config.serviceA.metadata.name: incomplete value string:
./problem2.cue:2:13
Expand Down Expand Up @@ -206,7 +206,7 @@ the concrete `metadata` values provided when `config` is declared?
The solution is: **use an alias!**

{{< code-tabs >}}
{{< code-tab name="solution.cue" language="cue" area="top-left" >}}
{{< code-tab name="solution.cue" language="cue" area="top-left" >}}
#Metadata: {
name: string
namespace: string
Expand Down Expand Up @@ -235,7 +235,7 @@ config: #Config & {
}
}
{{< /code-tab >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
{{< code-tab name="expected.yaml" language="yaml" area="top-right" >}}
config:
metadata:
name: test
Expand All @@ -249,7 +249,7 @@ config:
name: test
namespace: dev
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCBzb2x1dGlvbi5jdWUgLS1vdXQgeWFtbA==" >}}
$ cue export solution.cue --out yaml
config:
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ Given these two files, the `cue vet` command can verify that the values in
`ranges.yaml` are correct by just mentioning the two files on the command line.

{{< code-tabs >}}
{{< code-tab name="check.cue" language="cue" area="top-left" >}}
{{< code-tab name="check.cue" language="cue" area="top-left" >}}
min?: *0 | number // 0 if undefined

// must be strictly greater than min if defined.
max?: number & >min
{{< /code-tab >}}
{{< code-tab name="ranges.yaml" language="yaml" area="top-right" >}}
{{< code-tab name="ranges.yaml" language="yaml" area="top-right" >}}
min: 5
max: 10
---
min: 10
max: 5
{{< /code-tab >}}
{{< code-tab name="output" language="" area="bottom" >}}
{{< code-tab name="output" language="" area="bottom" >}}
max: invalid value 5 (out of bound >10):
./check.cue:4:16
./ranges.yaml:5:6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ and invoke the functions using its qualified identifier.
For instance:

{{< code-tabs >}}
{{< code-tab name="regexp.cue" language="cue" area="top" >}}
{{< code-tab name="regexp.cue" language="cue" area="top" >}}
import "regexp"

matches: regexp.FindSubmatch(#"^([^:]*):(\d+)$"#, "localhost:443")
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV2YWwgcmVnZXhwLmN1ZQ==" >}}
$ cue eval regexp.cue
matches: ["localhost:443", "localhost", "443"]
{{< /code-tab >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ One disadvantage is that it is very verbose.
Compare the following two equivalent schema definitions:

{{< code-tabs >}}
{{< code-tab name="native.cue" language="cue" area="top-left" >}}
{{< code-tab name="native.cue" language="cue" area="top-left" >}}
// Definitions.
info: version: "v1beta1"

Expand All @@ -181,7 +181,7 @@ info: version: "v1beta1"
max?: uint & <100
}
{{< /code-tab >}}
{{< code-tab name="openapi.json" language="json" area="top-right" >}}
{{< code-tab name="openapi.json" language="json" area="top-right" >}}
{
"openapi": "3.0.0",
"info": {
Expand Down
6 changes: 3 additions & 3 deletions hugo/content/en/docs/howto/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ that `cue` has caught the deliberate mistakes in our example data.
Here's an example:

{{< code-tabs >}}
{{< code-tab name="example.cue" language="cue" area="top-left" >}}
{{< code-tab name="example.cue" language="cue" area="top-left" >}}
package example

// CUE comments start with "//"
Expand All @@ -48,14 +48,14 @@ f1: string
// integer over 10
f2!: int & >10
{{< /code-tab >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
# f1 is actually an integer
f1: 123

# f2 is actually a string
f2: "some string value"
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="err" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="err" area="bottom" type="terminal" codetocopy="Y3VlIHZldCAuOmV4YW1wbGUgZGF0YS55bWw=" >}}
$ cue vet .:example data.yml
f1: conflicting values 123 and string (mismatched types int and string):
./data.yml:2:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The **`TERMINAL`** section shows the use of:
evaluation space

{{< code-tabs >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
package example

// inputs is the location under which we place
Expand All @@ -40,28 +40,28 @@ output: {
}
}
{{< /code-tab >}}
{{< code-tab name="a.json" language="json" area="top-left" >}}
{{< code-tab name="a.json" language="json" area="top-left" >}}
{
"a": 1,
"b": 2,
"c": 3
}
{{< /code-tab >}}
{{< code-tab name="b.json" language="json" area="top-left" >}}
{{< code-tab name="b.json" language="json" area="top-left" >}}
{
"a": "a string",
"b": true,
"c": 42
}
{{< /code-tab >}}
{{< code-tab name="c.json" language="json" area="top-left" >}}
{{< code-tab name="c.json" language="json" area="top-left" >}}
[
"a list element",
"another element",
"the last element"
]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCAtLXdpdGgtY29udGV4dCAtbCAnaW5wdXRzOicgLWwgJ3BhdGguQmFzZShmaWxlbmFtZSknIC1lIG91dHB1dCBhLmpzb24gYi5qc29uIGMuanNvbiBleGFtcGxlLmN1ZQ==" >}}
$ cue export --with-context -l 'inputs:' -l 'path.Base(filename)' -e output a.json b.json c.json example.cue
{
"a.json": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ This [Commented CUE]({{< relref "docs/howto/#commented-cue" >}}) demonstrates
how to use the `cue` command to combine multiple JSON files into a list.

{{< code-tabs >}}
{{< code-tab name="a.json" language="json" area="top-left" >}}
{{< code-tab name="a.json" language="json" area="top-left" >}}
{
"a": 1,
"b": "two",
"c": 33.3
}
{{< /code-tab >}}
{{< code-tab name="b.json" language="json" area="top-left" >}}
{{< code-tab name="b.json" language="json" area="top-left" >}}
{
"a": 22,
"b": "some string"
}
{{< /code-tab >}}
{{< code-tab name="c.json" language="json" area="top-left" >}}
{{< code-tab name="c.json" language="json" area="top-left" >}}
{
"a": 333,
"c": 42
}
{{< /code-tab >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
package example

import "list"
Expand Down Expand Up @@ -68,7 +68,7 @@ contents: [for _name in sortedInputs {
_inputs[_name]
}]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCAtLXdpdGgtY29udGV4dCAtbCAnX2lucHV0czonIC1sIGZpbGVuYW1lIGEuanNvbiBiLmpzb24gYy5qc29uIGV4YW1wbGUuY3Vl" >}}
$ cue export --with-context -l '_inputs:' -l filename a.json b.json c.json example.cue
{
"contents": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The **`TERMINAL`** section shows the use of:
evaluation space

{{< code-tabs >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
package example

// inputs is the location under which we place
Expand All @@ -40,22 +40,22 @@ output: {
}
}
{{< /code-tab >}}
{{< code-tab name="a.yaml" language="yaml" area="top-left" >}}
{{< code-tab name="a.yaml" language="yaml" area="top-left" >}}
a: 1
b: 2
c: 3
{{< /code-tab >}}
{{< code-tab name="b.yml" language="yml" area="top-left" >}}
{{< code-tab name="b.yml" language="yml" area="top-left" >}}
a: a string
b: true
c: 42
{{< /code-tab >}}
{{< code-tab name="c.yaml" language="yaml" area="top-left" >}}
{{< code-tab name="c.yaml" language="yaml" area="top-left" >}}
- a list element
- another element
- the last element
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCAtLXdpdGgtY29udGV4dCAtbCAnaW5wdXRzOicgLWwgJ3BhdGguQmFzZShmaWxlbmFtZSknIC1lIG91dHB1dCBhLnlhbWwgYi55bWwgYy55YW1sIGV4YW1wbGUuY3VlIC0tb3V0IHlhbWw=" >}}
$ cue export --with-context -l 'inputs:' -l 'path.Base(filename)' -e output a.yaml b.yml c.yaml example.cue --out yaml
a.yaml:
filename: a.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ This [Commented CUE]({{< relref "docs/howto/#commented-cue" >}}) demonstrates
how to use the `cue` command to combine multiple YAML files into a list.

{{< code-tabs >}}
{{< code-tab name="a.yaml" language="yaml" area="top-left" >}}
{{< code-tab name="a.yaml" language="yaml" area="top-left" >}}
a: 1
b: "two"
c: 33.3
{{< /code-tab >}}
{{< code-tab name="b.yml" language="yml" area="top-left" >}}
{{< code-tab name="b.yml" language="yml" area="top-left" >}}
a: 22
b: "some string"
{{< /code-tab >}}
{{< code-tab name="c.yaml" language="yaml" area="top-left" >}}
{{< code-tab name="c.yaml" language="yaml" area="top-left" >}}
a: 333
c: 42
{{< /code-tab >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
{{< code-tab name="example.cue" language="cue" area="top-right" >}}
package example

import "list"
Expand Down Expand Up @@ -62,7 +62,7 @@ contents: [for _name in sortedInputs {
_inputs[_name]
}]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCAtLXdpdGgtY29udGV4dCAtbCAnX2lucHV0czonIC1sIGZpbGVuYW1lIGEueWFtbCBiLnltbCBjLnlhbWwgZXhhbXBsZS5jdWUgLS1vdXQgeWFtbA==" >}}
$ cue export --with-context -l '_inputs:' -l filename a.yaml b.yml c.yaml example.cue --out yaml
contents:
- a: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ demonstrates how to constrain fields to contain string representations of
integer values.

{{< code-tabs >}}
{{< code-tab name="example.cue" language="cue" area="top-left" >}}
{{< code-tab name="example.cue" language="cue" area="top-left" >}}
package example

import "strconv"
Expand All @@ -31,14 +31,14 @@ import "strconv"
s1?: "\(strconv.Atoi(s1))"
s2?: "\(strconv.Atoi(s2))"
{{< /code-tab >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
# s1 is a valid integer
s1: "137"

# s2 is not a valid integer
s2: "42.7"
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="err" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="err" area="bottom" type="terminal" codetocopy="Y3VlIHZldCAuOmV4YW1wbGUgZGF0YS55bWw=" >}}
$ cue vet .:example data.yml
s2: invalid interpolation: error in call to strconv.Atoi: strconv.Atoi: parsing "42.7": invalid syntax:
./example.cue:9:6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bytes, and also in runes, as introduced by
[the Go programming language](https://go.dev/blog/strings#code-points-characters-and-runes).

{{< code-tabs >}}
{{< code-tab name="example.cue" language="cue" area="top" >}}
{{< code-tab name="example.cue" language="cue" area="top" >}}
package example

import "strings"
Expand Down Expand Up @@ -77,7 +77,7 @@ emoji_constrain_bytes: {
#bytes: len(content) & >=10
}
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="err" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="err" area="bottom" type="terminal" codetocopy="Y3VlIHZldCAuOmV4YW1wbGU=" >}}
$ cue vet .:example
ascii_constrain_runes: invalid value "only ASCII characters" (does not satisfy strings.MaxRunes(8)):
./example.cue:8:46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates constraining the sum of a list of numbers.

{{< code-tabs >}}
{{< code-tab name="schema.cue" language="cue" area="top-left" >}}
{{< code-tab name="schema.cue" language="cue" area="top-left" >}}
package example

import "list"
Expand All @@ -34,11 +34,11 @@ bad_list: [...number]
_good_sum: <=100 & list.Sum(good_list)
_bad_sum: <=99.5 & list.Sum(bad_list)
{{< /code-tab >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
{{< code-tab name="data.yml" language="yml" area="top-right" >}}
good_list: [ 1,2,3,4 ]
bad_list: [ 1,2,3,100.5 ]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="err" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="err" area="bottom" type="terminal" codetocopy="Y3VlIHZldCAuOmV4YW1wbGUgZGF0YS55bWw=" >}}
$ cue vet .:example data.yml
_bad_sum: invalid value 106.5 (out of bound <=99.5):
./schema.cue:14:12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates how to export these fields using `cue export -e`.

{{< code-tabs >}}
{{< code-tab name="data.yml" language="yml" area="top" >}}
{{< code-tab name="data.yml" language="yml" area="top" >}}
# data.yml contains a field we want to export with
# the "cue export" command's "-e" parameter

"top level field":
a: [ 1, 2, 3 ]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="bottom" >}}
{{< code-tab name="TERMINAL" language="" area="bottom" type="terminal" codetocopy="Y3VlIGV4cG9ydCAtbCBpbnB1dDogZGF0YS55bWwgLWUgJ2lucHV0WyJ0b3AgbGV2ZWwgZmllbGQiXSc=" >}}
$ cue export -l input: data.yml -e 'input["top level field"]'
{
"a": [
Expand Down
Loading

0 comments on commit 8e21d16

Please sign in to comment.