this repo has no description
0
fork

Configure Feed

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

pkg: reuse pkg/gen to generate package godocs

Instead of sprinkling copies of a tiny gen.go program to do so,
reuse pkg/gen which already knows how to generate for each package.
Each package has a different header, so we use doc.txt files in each.

Note that pkg/gen/packages.txt did not include the tool package itself.
We want to include it now to generate its godoc like the others,
but we don't want to start registering its package as it's not possible
to import it from CUE code today.

We might want to change that in the future, but for now, teach the
generator to skip registering the package to not change that detail.

Beyond the deduplication of code, this is also slightly faster,
as we have fewer go:generate programs to run:

$ time go generate ./...

real 0m10.926s
user 0m42.121s
sys 0m6.126s
$ git switch pkg-tool-generate
$ time go generate ./...

real 0m5.909s
user 0m14.437s
sys 0m3.311s

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I3a0ae6dbbe0766731655c4202b8c6059d1834a4e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/541844
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>

+371 -656
+46 -19
pkg/gen/gen.go
··· 58 58 var packages = strings.Fields(packagesStr) 59 59 60 60 type headerParams struct { 61 - GenFile string 62 - GoPkg string 63 - CUEPkg string 61 + GoPkg string 62 + CUEPkg string 63 + 64 + PackageDoc string 65 + PackageDefs string 64 66 } 65 67 66 68 var header = template.Must(template.New("").Parse( 67 69 `// Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 68 70 71 + {{if .PackageDoc}} 72 + {{.PackageDoc -}} 73 + // {{.PackageDefs}} 74 + {{end -}} 69 75 package {{.GoPkg}} 70 76 77 + {{if .CUEPkg -}} 71 78 import ( 72 79 "cuelang.org/go/internal/core/adt" 73 80 "cuelang.org/go/pkg/internal" ··· 78 85 } 79 86 80 87 var _ = adt.TopKind // in case the adt package isn't used 81 - 88 + {{end}} 82 89 `)) 83 90 84 91 func main() { ··· 122 129 fset: token.NewFileSet(), 123 130 } 124 131 125 - if err := header.Execute(g.w, headerParams{ 126 - GenFile: genFile, 127 - GoPkg: pkg.Name, 128 - CUEPkg: cuePkgPath, 129 - }); err != nil { 130 - return err 132 + params := headerParams{ 133 + GoPkg: pkg.Name, 134 + CUEPkg: cuePkgPath, 135 + } 136 + // As a special case, the "tool" package cannot be imported from CUE. 137 + skipRegister := params.CUEPkg == "tool" 138 + if skipRegister { 139 + params.CUEPkg = "" 131 140 } 132 141 133 - fmt.Fprintf(g.w, "var pkg = &internal.Package{\nNative: []*internal.Builtin{") 134 - g.first = true 135 - for _, filename := range pkg.GoFiles { 136 - if filename == genFile { 137 - continue 142 + if doc, err := os.ReadFile(filepath.Join(pkg.Dir, "doc.txt")); err == nil { 143 + defs, err := os.ReadFile(filepath.Join(pkg.Dir, pkg.Name+".cue")) 144 + if err != nil { 145 + return err 138 146 } 139 - g.processGo(filepath.Join(pkg.Dir, filename)) 147 + i := bytes.Index(defs, []byte("package "+pkg.Name)) 148 + defs = defs[i+len("package "+pkg.Name)+1:] 149 + defs = bytes.ReplaceAll(defs, []byte("\n"), []byte("\n// ")) 150 + params.PackageDoc = string(doc) 151 + params.PackageDefs = string(defs) 140 152 } 141 - fmt.Fprintf(g.w, "},\n") 142 - if err := g.processCUE(); err != nil { 153 + 154 + if err := header.Execute(g.w, params); err != nil { 143 155 return err 144 156 } 145 - fmt.Fprintf(g.w, "}\n") 157 + 158 + if !skipRegister { 159 + fmt.Fprintf(g.w, "var pkg = &internal.Package{\nNative: []*internal.Builtin{") 160 + g.first = true 161 + for _, filename := range pkg.GoFiles { 162 + if filename == genFile { 163 + continue 164 + } 165 + g.processGo(filepath.Join(pkg.Dir, filename)) 166 + } 167 + fmt.Fprintf(g.w, "},\n") 168 + if err := g.processCUE(); err != nil { 169 + return err 170 + } 171 + fmt.Fprintf(g.w, "}\n") 172 + } 146 173 147 174 b, err := format.Source(g.w.Bytes()) 148 175 if err != nil {
+1
pkg/gen/packages.txt
··· 17 17 crypto/md5 18 18 crypto/sha1 19 19 crypto/hmac 20 + tool 20 21 tool/os 21 22 tool/cli 22 23 tool/exec
-3
pkg/tool/cli/cli.go
··· 14 14 15 15 package cli 16 16 17 - //go:generate go run gen.go 18 - //go:generate gofmt -s -w . 19 - 20 17 import ( 21 18 "bufio" 22 19 "fmt"
-33
pkg/tool/cli/doc.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 2 - 3 - // Package cli provides tasks dealing with a console. 4 - // 5 - // These are the supported tasks: 6 - // 7 - // // Print sends text to the stdout of the current process. 8 - // Print: { 9 - // $id: *"tool/cli.Print" | "print" // for backwards compatibility 10 - // 11 - // // text is the text to be printed. 12 - // text: string 13 - // } 14 - // 15 - // // Ask prompts the current console with a message and waits for input. 16 - // // 17 - // // Example: 18 - // // task: ask: cli.Ask({ 19 - // // prompt: "Are you okay?" 20 - // // response: bool 21 - // // }) 22 - // Ask: { 23 - // $id: "tool/cli.Ask" 24 - // 25 - // // prompt sends this message to the output. 26 - // prompt: string 27 - // 28 - // // response holds the user's response. If it is a boolean expression it 29 - // // will interpret the answer using textual yes/ no. 30 - // response: string | bool 31 - // } 32 - // 33 - package cli
+3
pkg/tool/cli/doc.txt
··· 1 + // Package cli provides tasks dealing with a console. 2 + // 3 + // These are the supported tasks:
-47
pkg/tool/cli/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package cli provides tasks dealing with a console. 33 - // 34 - // These are the supported tasks: 35 - // %s 36 - package cli 37 - ` 38 - 39 - func main() { 40 - f, _ := os.Create("doc.go") 41 - defer f.Close() 42 - b, _ := ioutil.ReadFile("cli.cue") 43 - i := bytes.Index(b, []byte("package cli")) 44 - b = b[i+len("package cli")+1:] 45 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 46 - fmt.Fprintf(f, msg, string(b)) 47 - }
+30
pkg/tool/cli/pkg.go
··· 1 1 // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 + // Package cli provides tasks dealing with a console. 4 + // 5 + // These are the supported tasks: 6 + // 7 + // // Print sends text to the stdout of the current process. 8 + // Print: { 9 + // $id: *"tool/cli.Print" | "print" // for backwards compatibility 10 + // 11 + // // text is the text to be printed. 12 + // text: string 13 + // } 14 + // 15 + // // Ask prompts the current console with a message and waits for input. 16 + // // 17 + // // Example: 18 + // // task: ask: cli.Ask({ 19 + // // prompt: "Are you okay?" 20 + // // response: bool 21 + // // }) 22 + // Ask: { 23 + // $id: "tool/cli.Ask" 24 + // 25 + // // prompt sends this message to the output. 26 + // prompt: string 27 + // 28 + // // response holds the user's response. If it is a boolean expression it 29 + // // will interpret the answer using textual yes/ no. 30 + // response: string | bool 31 + // } 32 + // 3 33 package cli 4 34 5 35 import (
+1 -1
pkg/tool/doc.go pkg/tool/pkg.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 1 + // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 3 // Package tool defines stateful operation types for cue commands. 4 4 //
+18
pkg/tool/doc.txt
··· 1 + // Package tool defines stateful operation types for cue commands. 2 + // 3 + // This package is only visible in cue files with a _tool.cue or _tool_test.cue 4 + // ending. 5 + // 6 + // CUE configuration files are not influenced by and do not influence anything 7 + // outside the configuration itself: they are hermetic. Tools solve 8 + // two problems: allow outside values such as environment variables, 9 + // file or web contents, random generators etc. to influence configuration, 10 + // and allow configuration to be actionable from within the tooling itself. 11 + // Separating these concerns makes it clear to user when outside influences are 12 + // in play and the tool definition can be strict about what is allowed. 13 + // 14 + // Tools are defined in files ending with _tool.cue. These files have a 15 + // top-level map, "command", which defines all the tools made available through 16 + // the cue command. 17 + // 18 + // The following definitions are for defining commands in tool files:
-43
pkg/tool/exec/doc.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 2 - 3 - // Package exec defines tasks for running commands. 4 - // 5 - // These are the supported tasks: 6 - // 7 - // // Run executes the given shell command. 8 - // Run: { 9 - // $id: *"tool/exec.Run" | "exec" // exec for backwards compatibility 10 - // 11 - // // cmd is the command to run. 12 - // cmd: string | [string, ...string] 13 - // 14 - // // dir specifies the working directory of the command. 15 - // // The default is the current working directory. 16 - // dir?: string 17 - // 18 - // // env defines the environment variables to use for this system. 19 - // // If the value is a list, the entries mus be of the form key=value, 20 - // // where the last value takes precendence in the case of multiple 21 - // // occurrances of the same key. 22 - // env: [string]: string | [...=~"="] 23 - // 24 - // // stdout captures the output from stdout if it is of type bytes or string. 25 - // // The default value of null indicates it is redirected to the stdout of the 26 - // // current process. 27 - // stdout: *null | string | bytes 28 - // 29 - // // stderr is like stdout, but for errors. 30 - // stderr: *null | string | bytes 31 - // 32 - // // stdin specifies the input for the process. If stdin is null, the stdin 33 - // // of the current process is redirected to this command (the default). 34 - // // If it is of typ bytes or string, that input will be used instead. 35 - // stdin: *null | string | bytes 36 - // 37 - // // success is set to true when the process terminates with with a zero exit 38 - // // code or false otherwise. The user can explicitly specify the value 39 - // // force a fatal error if the desired success code is not reached. 40 - // success: bool 41 - // } 42 - // 43 - package exec
+3
pkg/tool/exec/doc.txt
··· 1 + // Package exec defines tasks for running commands. 2 + // 3 + // These are the supported tasks:
-3
pkg/tool/exec/exec.go
··· 14 14 15 15 package exec 16 16 17 - //go:generate go run gen.go 18 - //go:generate gofmt -s -w . 19 - 20 17 import ( 21 18 "fmt" 22 19 "os/exec"
-47
pkg/tool/exec/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package exec defines tasks for running commands. 33 - // 34 - // These are the supported tasks: 35 - // %s 36 - package exec 37 - ` 38 - 39 - func main() { 40 - f, _ := os.Create("doc.go") 41 - defer f.Close() 42 - b, _ := ioutil.ReadFile("exec.cue") 43 - i := bytes.Index(b, []byte("package exec")) 44 - b = b[i+len("package exec")+1:] 45 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 46 - fmt.Fprintf(f, msg, string(b)) 47 - }
+40
pkg/tool/exec/pkg.go
··· 1 1 // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 + // Package exec defines tasks for running commands. 4 + // 5 + // These are the supported tasks: 6 + // 7 + // // Run executes the given shell command. 8 + // Run: { 9 + // $id: *"tool/exec.Run" | "exec" // exec for backwards compatibility 10 + // 11 + // // cmd is the command to run. 12 + // cmd: string | [string, ...string] 13 + // 14 + // // dir specifies the working directory of the command. 15 + // // The default is the current working directory. 16 + // dir?: string 17 + // 18 + // // env defines the environment variables to use for this system. 19 + // // If the value is a list, the entries mus be of the form key=value, 20 + // // where the last value takes precendence in the case of multiple 21 + // // occurrances of the same key. 22 + // env: [string]: string | [...=~"="] 23 + // 24 + // // stdout captures the output from stdout if it is of type bytes or string. 25 + // // The default value of null indicates it is redirected to the stdout of the 26 + // // current process. 27 + // stdout: *null | string | bytes 28 + // 29 + // // stderr is like stdout, but for errors. 30 + // stderr: *null | string | bytes 31 + // 32 + // // stdin specifies the input for the process. If stdin is null, the stdin 33 + // // of the current process is redirected to this command (the default). 34 + // // If it is of typ bytes or string, that input will be used instead. 35 + // stdin: *null | string | bytes 36 + // 37 + // // success is set to true when the process terminates with with a zero exit 38 + // // code or false otherwise. The user can explicitly specify the value 39 + // // force a fatal error if the desired success code is not reached. 40 + // success: bool 41 + // } 42 + // 3 43 package exec 4 44 5 45 import (
-128
pkg/tool/file/doc.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 2 - 3 - // Package file provides file operations for cue tasks. 4 - // 5 - // These are the supported tasks: 6 - // 7 - // // Read reads the contents of a file. 8 - // Read: { 9 - // $id: "tool/file.Read" 10 - // 11 - // // filename names the file to read. 12 - // // 13 - // // Relative names are taken relative to the current working directory. 14 - // // Slashes are converted to the native OS path separator. 15 - // filename: !="" 16 - // 17 - // // contents is the read contents. If the contents are constraint to bytes 18 - // // (the default), the file is read as is. If it is constraint to a string, 19 - // // the contents are checked to be valid UTF-8. 20 - // contents: *bytes | string 21 - // } 22 - // 23 - // // Append writes contents to the given file. 24 - // Append: { 25 - // $id: "tool/file.Append" 26 - // 27 - // // filename names the file to append. 28 - // // 29 - // // Relative names are taken relative to the current working directory. 30 - // // Slashes are converted to the native OS path separator. 31 - // filename: !="" 32 - // 33 - // // permissions defines the permissions to use if the file does not yet exist. 34 - // permissions: int | *0o666 35 - // 36 - // // contents specifies the bytes to be written. 37 - // contents: bytes | string 38 - // } 39 - // 40 - // // Create writes contents to the given file. 41 - // Create: { 42 - // $id: "tool/file.Create" 43 - // 44 - // // filename names the file to write. 45 - // // 46 - // // Relative names are taken relative to the current working directory. 47 - // // Slashes are converted to the native OS path separator. 48 - // filename: !="" 49 - // 50 - // // permissions defines the permissions to use if the file does not yet exist. 51 - // permissions: int | *0o666 52 - // 53 - // // contents specifies the bytes to be written. 54 - // contents: bytes | string 55 - // } 56 - // 57 - // // Glob returns a list of files. 58 - // Glob: { 59 - // $id: "tool/file.Glob" 60 - // 61 - // // glob specifies the pattern to match files with. 62 - // // 63 - // // A relative pattern is taken relative to the current working directory. 64 - // // Slashes are converted to the native OS path separator. 65 - // glob: !="" 66 - // files: [...string] 67 - // } 68 - // 69 - // // Mkdir creates a directory at the specified path. 70 - // Mkdir: { 71 - // $id: "tool/file.Mkdir" 72 - // 73 - // // The directory path to create. 74 - // // If path is already a directory, Mkdir does nothing. 75 - // // If path already exists and is not a directory, Mkdir will return an error. 76 - // path: string 77 - // 78 - // // When true any necessary parents are created as well. 79 - // createParents: bool | *false 80 - // 81 - // // Directory mode and permission bits (before umask). 82 - // permissions: int | *0o755 83 - // } 84 - // 85 - // // MkdirAll creates a directory at the specified path along with any necessary 86 - // // parents. 87 - // // If path is already a directory, MkdirAll does nothing. 88 - // // If path already exists and is not a directory, MkdirAll will return an error. 89 - // MkdirAll: Mkdir & { 90 - // createParents: true 91 - // } 92 - // 93 - // // MkdirTemp creates a new temporary directory in the directory dir and sets 94 - // // the pathname of the new directory in path. 95 - // // It is the caller's responsibility to remove the directory when it is no 96 - // // longer needed. 97 - // MkdirTemp: { 98 - // $id: "tool/file.MkdirTemp" 99 - // 100 - // // The temporary directory is created in the directory specified by dir. 101 - // // If dir is the empty string, MkdirTemp uses the default directory for 102 - // // temporary files. 103 - // dir: string | *"" 104 - // 105 - // // The directory name is generated by adding a random string to the end of pattern. 106 - // // If pattern includes a "*", the random string replaces the last "*" instead. 107 - // pattern: string | *"" 108 - // 109 - // // The absolute path of the created directory. 110 - // path: string 111 - // } 112 - // 113 - // // RemoveAll removes path and any children it contains. 114 - // // It removes everything it can but returns the first error it encounters. 115 - // RemoveAll: { 116 - // $id: "tool/file.RemoveAll" 117 - // 118 - // // The path to remove. 119 - // // If the path does not exist, RemoveAll does nothing. 120 - // path: string 121 - // 122 - // // success contains the status of the removal. 123 - // // If path was removed success is set to true. 124 - // // If path didn't exists success is set to false. 125 - // success: bool 126 - // } 127 - // 128 - package file
+3
pkg/tool/file/doc.txt
··· 1 + // Package file provides file operations for cue tasks. 2 + // 3 + // These are the supported tasks:
-3
pkg/tool/file/file.go
··· 14 14 15 15 package file 16 16 17 - //go:generate go run gen.go 18 - //go:generate gofmt -s -w . 19 - 20 17 import ( 21 18 "io/ioutil" 22 19 "os"
-47
pkg/tool/file/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package file provides file operations for cue tasks. 33 - // 34 - // These are the supported tasks: 35 - // %s 36 - package file 37 - ` 38 - 39 - func main() { 40 - f, _ := os.Create("doc.go") 41 - defer f.Close() 42 - b, _ := ioutil.ReadFile("file.cue") 43 - i := bytes.Index(b, []byte("package file")) 44 - b = b[i+len("package file")+1:] 45 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 46 - fmt.Fprintf(f, msg, string(b)) 47 - }
+125
pkg/tool/file/pkg.go
··· 1 1 // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 + // Package file provides file operations for cue tasks. 4 + // 5 + // These are the supported tasks: 6 + // 7 + // // Read reads the contents of a file. 8 + // Read: { 9 + // $id: "tool/file.Read" 10 + // 11 + // // filename names the file to read. 12 + // // 13 + // // Relative names are taken relative to the current working directory. 14 + // // Slashes are converted to the native OS path separator. 15 + // filename: !="" 16 + // 17 + // // contents is the read contents. If the contents are constraint to bytes 18 + // // (the default), the file is read as is. If it is constraint to a string, 19 + // // the contents are checked to be valid UTF-8. 20 + // contents: *bytes | string 21 + // } 22 + // 23 + // // Append writes contents to the given file. 24 + // Append: { 25 + // $id: "tool/file.Append" 26 + // 27 + // // filename names the file to append. 28 + // // 29 + // // Relative names are taken relative to the current working directory. 30 + // // Slashes are converted to the native OS path separator. 31 + // filename: !="" 32 + // 33 + // // permissions defines the permissions to use if the file does not yet exist. 34 + // permissions: int | *0o666 35 + // 36 + // // contents specifies the bytes to be written. 37 + // contents: bytes | string 38 + // } 39 + // 40 + // // Create writes contents to the given file. 41 + // Create: { 42 + // $id: "tool/file.Create" 43 + // 44 + // // filename names the file to write. 45 + // // 46 + // // Relative names are taken relative to the current working directory. 47 + // // Slashes are converted to the native OS path separator. 48 + // filename: !="" 49 + // 50 + // // permissions defines the permissions to use if the file does not yet exist. 51 + // permissions: int | *0o666 52 + // 53 + // // contents specifies the bytes to be written. 54 + // contents: bytes | string 55 + // } 56 + // 57 + // // Glob returns a list of files. 58 + // Glob: { 59 + // $id: "tool/file.Glob" 60 + // 61 + // // glob specifies the pattern to match files with. 62 + // // 63 + // // A relative pattern is taken relative to the current working directory. 64 + // // Slashes are converted to the native OS path separator. 65 + // glob: !="" 66 + // files: [...string] 67 + // } 68 + // 69 + // // Mkdir creates a directory at the specified path. 70 + // Mkdir: { 71 + // $id: "tool/file.Mkdir" 72 + // 73 + // // The directory path to create. 74 + // // If path is already a directory, Mkdir does nothing. 75 + // // If path already exists and is not a directory, Mkdir will return an error. 76 + // path: string 77 + // 78 + // // When true any necessary parents are created as well. 79 + // createParents: bool | *false 80 + // 81 + // // Directory mode and permission bits (before umask). 82 + // permissions: int | *0o755 83 + // } 84 + // 85 + // // MkdirAll creates a directory at the specified path along with any necessary 86 + // // parents. 87 + // // If path is already a directory, MkdirAll does nothing. 88 + // // If path already exists and is not a directory, MkdirAll will return an error. 89 + // MkdirAll: Mkdir & { 90 + // createParents: true 91 + // } 92 + // 93 + // // MkdirTemp creates a new temporary directory in the directory dir and sets 94 + // // the pathname of the new directory in path. 95 + // // It is the caller's responsibility to remove the directory when it is no 96 + // // longer needed. 97 + // MkdirTemp: { 98 + // $id: "tool/file.MkdirTemp" 99 + // 100 + // // The temporary directory is created in the directory specified by dir. 101 + // // If dir is the empty string, MkdirTemp uses the default directory for 102 + // // temporary files. 103 + // dir: string | *"" 104 + // 105 + // // The directory name is generated by adding a random string to the end of pattern. 106 + // // If pattern includes a "*", the random string replaces the last "*" instead. 107 + // pattern: string | *"" 108 + // 109 + // // The absolute path of the created directory. 110 + // path: string 111 + // } 112 + // 113 + // // RemoveAll removes path and any children it contains. 114 + // // It removes everything it can but returns the first error it encounters. 115 + // RemoveAll: { 116 + // $id: "tool/file.RemoveAll" 117 + // 118 + // // The path to remove. 119 + // // If the path does not exist, RemoveAll does nothing. 120 + // path: string 121 + // 122 + // // success contains the status of the removal. 123 + // // If path was removed success is set to true. 124 + // // If path didn't exists success is set to false. 125 + // success: bool 126 + // } 127 + // 3 128 package file 4 129 5 130 import (
-62
pkg/tool/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package tool defines stateful operation types for cue commands. 33 - // 34 - // This package is only visible in cue files with a _tool.cue or _tool_test.cue 35 - // ending. 36 - // 37 - // CUE configuration files are not influenced by and do not influence anything 38 - // outside the configuration itself: they are hermetic. Tools solve 39 - // two problems: allow outside values such as environment variables, 40 - // file or web contents, random generators etc. to influence configuration, 41 - // and allow configuration to be actionable from within the tooling itself. 42 - // Separating these concerns makes it clear to user when outside influences are 43 - // in play and the tool definition can be strict about what is allowed. 44 - // 45 - // Tools are defined in files ending with _tool.cue. These files have a 46 - // top-level map, "command", which defines all the tools made available through 47 - // the cue command. 48 - // 49 - // The following definitions are for defining commands in tool files: 50 - // %s 51 - package tool 52 - ` 53 - 54 - func main() { 55 - f, _ := os.Create("doc.go") 56 - defer f.Close() 57 - b, _ := ioutil.ReadFile("tool.cue") 58 - i := bytes.Index(b, []byte("package tool")) 59 - b = b[i+len("package tool")+1:] 60 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 61 - fmt.Fprintf(f, msg, string(b)) 62 - }
-18
pkg/tool/generate.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - package tool 16 - 17 - //go:generate go run gen.go 18 - //go:generate go fmt
-53
pkg/tool/http/doc.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 2 - 3 - // Package http provides tasks related to the HTTP protocol. 4 - // 5 - // These are the supported tasks: 6 - // 7 - // Get: Do & {method: "GET"} 8 - // Post: Do & {method: "POST"} 9 - // Put: Do & {method: "PUT"} 10 - // Delete: Do & {method: "DELETE"} 11 - // 12 - // Do: { 13 - // $id: *"tool/http.Do" | "http" // http for backwards compatibility 14 - // 15 - // method: string 16 - // url: string // TODO: make url.URL type 17 - // 18 - // tls: { 19 - // // Whether the server certificate must be validated. 20 - // verify: *true | bool 21 - // // PEM encoded certificate(s) to validate the server certificate. 22 - // // If not set the CA bundle of the system is used. 23 - // caCert?: bytes | string 24 - // } 25 - // 26 - // request: { 27 - // body?: bytes | string 28 - // header: [string]: string | [...string] 29 - // trailer: [string]: string | [...string] 30 - // } 31 - // response: { 32 - // status: string 33 - // statusCode: int 34 - // 35 - // body: *bytes | string 36 - // header: [string]: string | [...string] 37 - // trailer: [string]: string | [...string] 38 - // } 39 - // } 40 - // 41 - // // TODO: support serving once we have the cue serve command. 42 - // // Serve: { 43 - // // port: int 44 - // // 45 - // // cert: string 46 - // // key: string 47 - // // 48 - // // handle: [Pattern=string]: Message & { 49 - // // pattern: Pattern 50 - // // } 51 - // // } 52 - // 53 - package http
+3
pkg/tool/http/doc.txt
··· 1 + // Package http provides tasks related to the HTTP protocol. 2 + // 3 + // These are the supported tasks:
-47
pkg/tool/http/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package http provides tasks related to the HTTP protocol. 33 - // 34 - // These are the supported tasks: 35 - // %s 36 - package http 37 - ` 38 - 39 - func main() { 40 - f, _ := os.Create("doc.go") 41 - defer f.Close() 42 - b, _ := ioutil.ReadFile("http.cue") 43 - i := bytes.Index(b, []byte("package http")) 44 - b = b[i+len("package http")+1:] 45 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 46 - fmt.Fprintf(f, msg, string(b)) 47 - }
-3
pkg/tool/http/http.go
··· 14 14 15 15 package http 16 16 17 - //go:generate go run gen.go 18 - //go:generate gofmt -s -w . 19 - 20 17 import ( 21 18 "bytes" 22 19 "crypto/tls"
+50
pkg/tool/http/pkg.go
··· 1 1 // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 + // Package http provides tasks related to the HTTP protocol. 4 + // 5 + // These are the supported tasks: 6 + // 7 + // Get: Do & {method: "GET"} 8 + // Post: Do & {method: "POST"} 9 + // Put: Do & {method: "PUT"} 10 + // Delete: Do & {method: "DELETE"} 11 + // 12 + // Do: { 13 + // $id: *"tool/http.Do" | "http" // http for backwards compatibility 14 + // 15 + // method: string 16 + // url: string // TODO: make url.URL type 17 + // 18 + // tls: { 19 + // // Whether the server certificate must be validated. 20 + // verify: *true | bool 21 + // // PEM encoded certificate(s) to validate the server certificate. 22 + // // If not set the CA bundle of the system is used. 23 + // caCert?: bytes | string 24 + // } 25 + // 26 + // request: { 27 + // body?: bytes | string 28 + // header: [string]: string | [...string] 29 + // trailer: [string]: string | [...string] 30 + // } 31 + // response: { 32 + // status: string 33 + // statusCode: int 34 + // 35 + // body: *bytes | string 36 + // header: [string]: string | [...string] 37 + // trailer: [string]: string | [...string] 38 + // } 39 + // } 40 + // 41 + // // TODO: support serving once we have the cue serve command. 42 + // // Serve: { 43 + // // port: int 44 + // // 45 + // // cert: string 46 + // // key: string 47 + // // 48 + // // handle: [Pattern=string]: Message & { 49 + // // pattern: Pattern 50 + // // } 51 + // // } 52 + // 3 53 package http 4 54 5 55 import (
-48
pkg/tool/os/doc.go
··· 1 - // Code generated by cue get go. DO NOT EDIT. 2 - 3 - // Package os defines tasks for retrieving os-related information. 4 - // 5 - // CUE definitions: 6 - // 7 - // // A Value are all possible values allowed in flags. 8 - // // A null value unsets an environment variable. 9 - // Value: bool | number | *string | null 10 - // 11 - // // Name indicates a valid flag name. 12 - // Name: !="" & !~"^[$]" 13 - // 14 - // // Setenv defines a set of command line flags, the values of which will be set 15 - // // at run time. The doc comment of the flag is presented to the user in help. 16 - // // 17 - // // To define a shorthand, define the shorthand as a new flag referring to 18 - // // the flag of which it is a shorthand. 19 - // Setenv: { 20 - // $id: "tool/os.Setenv" 21 - // 22 - // {[Name]: Value} 23 - // } 24 - // 25 - // // Getenv gets and parses the specific command line variables. 26 - // Getenv: { 27 - // $id: "tool/os.Getenv" 28 - // 29 - // {[Name]: Value} 30 - // } 31 - // 32 - // // Environ populates a struct with all environment variables. 33 - // Environ: { 34 - // $id: "tool/os.Environ" 35 - // 36 - // // A map of all populated values. 37 - // // Individual entries may be specified ahead of time to enable 38 - // // validation and parsing. Values that are marked as required 39 - // // will fail the task if they are not found. 40 - // {[Name]: Value} 41 - // } 42 - // 43 - // // Clearenv clears all environment variables. 44 - // Clearenv: { 45 - // $id: "tool/os.Clearenv" 46 - // } 47 - // 48 - package os
+3
pkg/tool/os/doc.txt
··· 1 + // Package os defines tasks for retrieving os-related information. 2 + // 3 + // CUE definitions:
-3
pkg/tool/os/env.go
··· 14 14 15 15 package os 16 16 17 - //go:generate go run gen.go 18 - //go:generate gofmt -s -w . 19 - 20 17 import ( 21 18 "os" 22 19 "strings"
-48
pkg/tool/os/gen.go
··· 1 - // Copyright 2019 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build ignore 16 - // +build ignore 17 - 18 - package main 19 - 20 - // TODO: remove when we have a cuedoc server. Until then, 21 - // piggyback on pkg.go.dev. 22 - 23 - import ( 24 - "bytes" 25 - "fmt" 26 - "io/ioutil" 27 - "os" 28 - ) 29 - 30 - const msg = `// Code generated by cue get go. DO NOT EDIT. 31 - 32 - // Package os defines tasks for retrieving os-related information. 33 - // 34 - // CUE definitions: 35 - // %s 36 - package os 37 - ` 38 - 39 - func main() { 40 - f, _ := os.Create("doc.go") 41 - defer f.Close() 42 - b, _ := ioutil.ReadFile("os.cue") 43 - i := bytes.Index(b, []byte("package os")) 44 - b = b[i+len("package os")+1:] 45 - b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n// ")) 46 - b = bytes.ReplaceAll(b, []byte("\t"), []byte(" ")) 47 - fmt.Fprintf(f, msg, string(b)) 48 - }
+45
pkg/tool/os/pkg.go
··· 1 1 // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 2 2 3 + // Package os defines tasks for retrieving os-related information. 4 + // 5 + // CUE definitions: 6 + // 7 + // // A Value are all possible values allowed in flags. 8 + // // A null value unsets an environment variable. 9 + // Value: bool | number | *string | null 10 + // 11 + // // Name indicates a valid flag name. 12 + // Name: !="" & !~"^[$]" 13 + // 14 + // // Setenv defines a set of command line flags, the values of which will be set 15 + // // at run time. The doc comment of the flag is presented to the user in help. 16 + // // 17 + // // To define a shorthand, define the shorthand as a new flag referring to 18 + // // the flag of which it is a shorthand. 19 + // Setenv: { 20 + // $id: "tool/os.Setenv" 21 + // 22 + // {[Name]: Value} 23 + // } 24 + // 25 + // // Getenv gets and parses the specific command line variables. 26 + // Getenv: { 27 + // $id: "tool/os.Getenv" 28 + // 29 + // {[Name]: Value} 30 + // } 31 + // 32 + // // Environ populates a struct with all environment variables. 33 + // Environ: { 34 + // $id: "tool/os.Environ" 35 + // 36 + // // A map of all populated values. 37 + // // Individual entries may be specified ahead of time to enable 38 + // // validation and parsing. Values that are marked as required 39 + // // will fail the task if they are not found. 40 + // {[Name]: Value} 41 + // } 42 + // 43 + // // Clearenv clears all environment variables. 44 + // Clearenv: { 45 + // $id: "tool/os.Clearenv" 46 + // } 47 + // 3 48 package os 4 49 5 50 import (