cmd/cue/cmd: update more examples to the new format
Closes #62
Change-Id: Ib9323184257da77d14d6de456d35e45b425f20c0
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3873
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/cmd.go b/cmd/cue/cmd/cmd.go
index 0f928ab..6be5382 100644
--- a/cmd/cue/cmd/cmd.go
+++ b/cmd/cue/cmd/cmd.go
@@ -49,7 +49,7 @@
Commands are defined at the top-level of the configuration:
- command <Name>: { // from tool.Command
+ command: [Name=string]: { // from tool.Command
// usage gives a short usage pattern of the command.
// Example:
// fmt [-n] [-x] [packages]
@@ -68,7 +68,7 @@
// Each task can have inputs and outputs, depending on the type
// task. The outputs are initially unspecified, but are filled out
// by the tooling
- task <Name>: { // from "tool".Task
+ task: [string]: { // from "tool".Task
// supported fields depend on type
}
@@ -83,7 +83,7 @@
// The tool would print documentation of this flag as:
// Flags:
// --env string environment to run in: test(default) or prod
- var <Name>: VarValue
+ var: [string]: VarValue
// flag defines a command line flag.
//
@@ -100,7 +100,7 @@
// Flags:
// -e, --env string environment to run in: test(default), staging, or prod
//
- flag <Name>: { // from "tool".Flag
+ flag [Name=_]: { // from "tool".Flag
// value defines the possible values for this flag.
// The default is string. Users can define default values by
// using disjunctions.
@@ -116,7 +116,9 @@
}
// populate flag with the default values for
- flag: { "\(k)": { value: v } | null for k, v in var }
+ for k, v in var {
+ flag: { "\(k)": { value: v } | null }
+ }
// env defines environment variables. It is populated with values
// for var.
@@ -128,7 +130,7 @@
// var foo: string
// env foo: null // don't use environment variables for foo
//
- env <Name>: {
+ env: [Name=_]: {
// name defines the environment variable that sets this flag.
name?: *"CUE_VAR_" + strings.Upper(Name) | string
@@ -136,7 +138,11 @@
// if not set.
value?: string | bytes
}
- env: { "\(k)": { value: v } | null for k, v in var }
+ env: {
+ for k, v in var {
+ "\(k)": { value: v } | null
+ }
+ }
}
Available tasks can be found in the package documentation at
@@ -157,11 +163,11 @@
city: "Amsterdam"
// Say hello!
- command hello: {
+ command: hello: {
// whom to say hello to
- var who: *"World" | string
+ var: who: *"World" | string
- task print: exec.Run & {
+ task: print: exec.Run & {
cmd: "echo Hello \(var.who)! Welcome to \(city)."
}
}
@@ -183,28 +189,28 @@
city: "Amsterdam"
// Say hello!
- command hello: {
- var file: "out.txt" | string // save transcript to this file
+ command: hello: {
+ var: file: "out.txt" | string // save transcript to this file
- task ask: cli.Ask & {
+ task: ask: cli.Ask & {
prompt: "What is your name?"
response: string
}
// starts after ask
- task echo: exec.Run & {
+ task: echo: exec.Run & {
cmd: ["echo", "Hello", task.ask.response + "!"]
stdout: string // capture stdout
}
// starts after echo
- task write: file.Append & {
+ task: write: file.Append & {
filename: var.file
contents: task.echo.stdout
}
// also starts after echo
- task print: cli.Print & {
+ task: print: cli.Print & {
contents: task.echo.stdout
}
}
diff --git a/cmd/cue/cmd/import.go b/cmd/cue/cmd/import.go
index 802e874..1460bc8 100644
--- a/cmd/cue/cmd/import.go
+++ b/cmd/cue/cmd/import.go
@@ -129,12 +129,12 @@
# base the path values on th input
$ cue import -f -l '"\(strings.ToLower(kind))" "\(x.name)"' foo.yaml
$ cat foo.cue
- service booster: {
+ service: booster: {
kind: "Service"
name: "booster"
}
- deployment booster: {
+ deployment: booster: {
kind: "Deployment"
name: "booster
replicas: 1
@@ -184,11 +184,11 @@
$ cue import -R example.json
$ cat example.cue
- import "encode/json"
+ import "encoding/json"
a: {
data: json.Encode(_data),
- _data: {
+ _data = {
foo: 1
bar: 2
}
@@ -690,6 +690,7 @@
ast.NewSel(pkg, "Marshal"),
ast.NewIdent(dataField))
+ // TODO: use definitions instead
c.InsertAfter(astutil.ApplyRecursively(&ast.Alias{
Ident: ast.NewIdent(dataField),
Expr: expr,