this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg/tool: add constraints for tasks

Updates #39

Change-Id: I9036a366a798cb2cd08d6e4695c1ab9e6d32da66
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1940
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>

authored by

Marcel van Lohuizen and committed by
Marcel van Lohuizen
928bfa36 e900d0d7

+25 -149
+1 -1
cmd/cue/cmd/testdata/tasks/cmd_baddisplay.out
··· 1 1 unsupported op &(number, (string)*): 2 2 $CWD/testdata/tasks/task_tool.cue:29:9 3 - tool/cli:4:10 3 + tool/cli:4:9 4 4
+7 -1
cue/builtin.go
··· 233 233 234 234 func initBuiltins(pkgs map[string]*builtinPkg) { 235 235 ctx := sharedIndex.newContext() 236 - for k, b := range pkgs { 236 + keys := []string{} 237 + for k := range pkgs { 238 + keys = append(keys, k) 239 + } 240 + sort.Strings(keys) 241 + for _, k := range keys { 242 + b := pkgs[k] 237 243 e := mustCompileBuiltins(ctx, b, k) 238 244 builtins[k] = e 239 245 builtins["-/"+path.Base(k)] = e
+5 -13
cue/builtins.go
··· 1874 1874 usage?: string 1875 1875 short?: string 1876 1876 long?: string 1877 - var <name>: { 1878 - value: _ 1879 - description: "" | string 1880 - } 1881 1877 tasks <name>: Task 1882 1878 } 1883 - Task _kind: =~"\\." 1879 + Task kind: =~"\\." 1884 1880 }`, 1885 1881 }, 1886 1882 "tool/cli": &builtinPkg{ 1887 1883 native: []*builtin{{}}, 1888 1884 cue: `{ 1889 1885 Print: { 1890 - _kind: "tool/cli.Print" 1891 - text: string 1886 + kind: *"tool/cli.Print" | "print" 1887 + text: string 1892 1888 } 1893 1889 }`, 1894 1890 }, ··· 1896 1892 native: []*builtin{{}}, 1897 1893 cue: `{ 1898 1894 Run: { 1899 - _kind: "tool/exec.Run" 1895 + kind: *"tool/exec.Run" | "exec" 1900 1896 cmd: string | [string, ...string] 1901 1897 install?: string | [string, ...string] 1902 1898 env <Key>: string ··· 1904 1900 stderr: *null | string | bytes 1905 1901 stdin?: string | bytes 1906 1902 success: bool 1907 - } 1908 - Env: { 1909 - _kind: "tool/exec.Env" 1910 - env <Name>: string | number 1911 1903 } 1912 1904 }`, 1913 1905 }, ··· 1946 1938 method: "GET" 1947 1939 } 1948 1940 Do: { 1949 - _kind: "tool/http.Do" 1941 + kind: *"tool/http.Do" | "http" 1950 1942 method: string 1951 1943 response: { 1952 1944 body: *bytes | string
+3
cue/gen.go
··· 231 231 switch x.Tok { 232 232 case token.CONST: 233 233 for _, spec := range x.Specs { 234 + if !ast.IsExported(spec.(*ast.ValueSpec).Names[0].Name) { 235 + continue 236 + } 234 237 g.genConst(spec.(*ast.ValueSpec)) 235 238 } 236 239 case token.IMPORT:
+1 -1
pkg/tool/cli/cli.cue
··· 16 16 17 17 // Print sends text to the stdout of the current process. 18 18 Print: { 19 - kind: "tool/cli.Print" 19 + kind: *"tool/cli.Print" | "print" // for backwards compatibility 20 20 21 21 // text is the text to be printed. 22 22 text: string
+3 -1
pkg/tool/exec/exec.cue
··· 16 16 17 17 // Run executes the given shell command. 18 18 Run: { 19 - kind: "tool/exec.Run" 19 + kind: *"tool/exec.Run" | "exec" // exec for backwards compatibility 20 20 21 21 // cmd is the command to run. 22 22 cmd: string | [string, ...string] ··· 45 45 success: bool 46 46 } 47 47 48 + /* TODO 48 49 // Env collects the environment variables of the current process. 49 50 Env: { 50 51 kind: "tool/exec.Env" 51 52 52 53 env <Name>: string | number 53 54 } 55 + */
+1 -1
pkg/tool/http/http.cue
··· 20 20 Delete: Do & {method: "DELETE"} 21 21 22 22 Do: { 23 - kind: "tool/http.Do" 23 + kind: *"tool/http.Do" | "http" // http for backwards compatibility 24 24 25 25 method: string 26 26 url: string // TODO: make url.URL type
-1
pkg/tool/http/http.go
··· 46 46 } 47 47 48 48 func (c *httpCmd) Run(ctx *task.Context, v cue.Value) (res interface{}, err error) { 49 - // v.Validate() 50 49 var header, trailer http.Header 51 50 method := lookupString(v, "method") 52 51 u := lookupString(v, "url")
+4 -130
pkg/tool/tool.cue
··· 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 14 15 - // Package tool defines statefull operation types for cue commands. 16 - // 17 - // This package is only visible in cue files with a _tool.cue or _tool_test.cue 18 - // ending. 19 - // 20 - // CUE configuration files are not influenced by and do not influence anything 21 - // outside the configuration itself: they are hermetic. Tools solve 22 - // two problems: allow outside values such as environment variables, 23 - // file or web contents, random generators etc. to influence configuration, 24 - // and allow configuration to be actionable from within the tooling itself. 25 - // Separating these concerns makes it clear to user when outside influences are 26 - // in play and the tool definition can be strict about what is allowed. 27 - // 28 - // Tools are defined in files ending with _tool.cue. These files have a 29 - // top-level map, "command", which defines all the tools made available through 30 - // the cue command. 31 - // 32 - // 33 15 package tool 34 16 35 17 // A Command specifies a user-defined command. ··· 46 28 // likely contain examples of usage of the command. 47 29 long?: string 48 30 49 - // A var defines a value that can be set by the command line or an 50 - // environment variable. 51 - // 52 - // Example: 53 - // var fast: { 54 - // description: "run faster than anyone" 55 - // value: true | bool 56 - // } 57 - // 58 - var <name>: { 59 - value: _ 60 - description: "" | string 61 - } 31 + // TODO: define flags and environment variables. 62 32 63 33 // tasks specifies the list of things to do to run command. Tasks are 64 34 // typically underspecified and completed by the particular internal 65 35 // handler that is running them. Task de 66 36 tasks <name>: Task 67 - 68 - // TODO: 69 - // timeout?: number // in seconds 70 37 } 71 38 72 - // A task defines a step in the execution of a command, server, or fix 73 - // operation. 39 + // A Task defines a step in the execution of a command. 74 40 Task: { 41 + // kind indicates the operation to run. It must be of the form 42 + // packagePath.Operation. 75 43 kind: =~#"\."# 76 44 } 77 - 78 - // import "cue/tool" 79 - // 80 - // command <Name>: { // from "cue/tool".Command 81 - // // usage gives a short usage pattern of the command. 82 - // // Example: 83 - // // fmt [-n] [-x] [packages] 84 - // usage: Name | string 85 - // 86 - // // short gives a brief on-line description of the command. 87 - // // Example: 88 - // // reformat package sources 89 - // short: "" | string 90 - // 91 - // // long gives a detailed description of the command, including a 92 - // // description of flags usage and examples. 93 - // long: "" | string 94 - // 95 - // // A task defines a single action to be run as part of this command. 96 - // // Each task can have inputs and outputs, depending on the type 97 - // // task. The outputs are initially unspecified, but are filled out 98 - // // by the tooling 99 - // // 100 - // task <Name>: { // from "cue/tool".Task 101 - // // supported fields depend on type 102 - // } 103 - // 104 - // VarValue = string | bool | int | float | [...string|int|float] 105 - // 106 - // // var declares values that can be set by command line flags or 107 - // // environment variables. 108 - // // 109 - // // Example: 110 - // // // environment to run in 111 - // // var env: "test" | "prod" 112 - // // The tool would print documentation of this flag as: 113 - // // Flags: 114 - // // --env string environment to run in: test(default) or prod 115 - // var <Name>: VarValue 116 - // 117 - // // flag defines a command line flag. 118 - // // 119 - // // Example: 120 - // // var env: "test" | "prod" 121 - // // 122 - // // // augment the flag information for var 123 - // // flag env: { 124 - // // shortFlag: "e" 125 - // // description: "environment to run in" 126 - // // } 127 - // // 128 - // // The tool would print documentation of this flag as: 129 - // // Flags: 130 - // // -e, --env string environment to run in: test(default), staging, or prod 131 - // // 132 - // flag <Name>: { // from "cue/tool".Flag 133 - // // value defines the possible values for this flag. 134 - // // The default is string. Users can define default values by 135 - // // using disjunctions. 136 - // value: env[Name].value | VarValue 137 - // 138 - // // name, if set, allows var to be set with the command-line flag 139 - // // of the given name. null disables the command line flag. 140 - // name: Name | null | string 141 - // 142 - // // short defines an abbreviated version of the flag. 143 - // // Disabled by default. 144 - // short: null | string 145 - // } 146 - // 147 - // // populate flag with the default values for 148 - // flag: { "\(k)": { value: v } | null for k, v in var } 149 - // 150 - // // env defines environment variables. It is populated with values 151 - // // for var. 152 - // // 153 - // // To specify a var without an equivalent environment variable, 154 - // // either specify it as a flag directly or disable the equally 155 - // // named env entry explicitly: 156 - // // 157 - // // var foo: string 158 - // // env foo: null // don't use environment variables for foo 159 - // // 160 - // env <Name>: {å 161 - // // name defines the environment variable that sets this flag. 162 - // name: "CUE_VAR_" + strings.Upper(Name) | string | null 163 - // 164 - // // The value retrieved from the environment variable or null 165 - // // if not set. 166 - // value: null | string | bytes 167 - // } 168 - // env: { "\(k)": { value: v } | null for k, v in var } 169 - // } 170 - //