cuelang.org/go@v0.13.0/pkg/tool/file/file.cue (about) 1 // Copyright 2018 The 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 file 16 17 // Read reads the contents of a file. 18 Read: { 19 $id: _id 20 _id: "tool/file.Read" 21 22 // filename names the file to read. 23 // 24 // Relative names are taken relative to the current working directory. 25 // Slashes are converted to the native OS path separator. 26 filename: !="" 27 28 // contents is the read contents. If the contents are constraint to bytes 29 // (the default), the file is read as is. If it is constraint to a string, 30 // the contents are checked to be valid UTF-8. 31 contents: *bytes | string 32 } 33 34 // Append writes contents to the given file. 35 Append: { 36 $id: _id 37 _id: "tool/file.Append" 38 39 // filename names the file to append. 40 // 41 // Relative names are taken relative to the current working directory. 42 // Slashes are converted to the native OS path separator. 43 filename: !="" 44 45 // permissions defines the permissions to use if the file does not yet exist. 46 permissions: int | *0o666 47 48 // contents specifies the bytes to be written. 49 contents: bytes | string 50 } 51 52 // Create writes contents to the given file. 53 Create: { 54 $id: _id 55 _id: "tool/file.Create" 56 57 // filename names the file to write. 58 // 59 // Relative names are taken relative to the current working directory. 60 // Slashes are converted to the native OS path separator. 61 filename: !="" 62 63 // permissions defines the permissions to use if the file does not yet exist. 64 permissions: int | *0o666 65 66 // contents specifies the bytes to be written. 67 contents: bytes | string 68 } 69 70 // Glob returns a list of files. 71 Glob: { 72 $id: _id 73 _id: "tool/file.Glob" 74 75 // glob specifies the pattern to match files with. 76 // 77 // A relative pattern is taken relative to the current working directory. 78 // Slashes are converted to the native OS path separator. 79 glob: !="" 80 files: [...string] 81 } 82 83 // Mkdir creates a directory at the specified path. 84 Mkdir: { 85 $id: _id 86 _id: "tool/file.Mkdir" 87 88 // The directory path to create. 89 // If path is already a directory, Mkdir does nothing. 90 // If path already exists and is not a directory, Mkdir will return an error. 91 path: string 92 93 // When true any necessary parents are created as well. 94 createParents: bool | *false 95 96 // Directory mode and permission bits (before umask). 97 permissions: int | *0o777 98 } 99 100 // MkdirAll creates a directory at the specified path along with any necessary 101 // parents. 102 // If path is already a directory, MkdirAll does nothing. 103 // If path already exists and is not a directory, MkdirAll will return an error. 104 MkdirAll: Mkdir & { 105 createParents: true 106 } 107 108 // MkdirTemp creates a new temporary directory in the directory dir and sets 109 // the pathname of the new directory in path. 110 // It is the caller's responsibility to remove the directory when it is no 111 // longer needed. 112 MkdirTemp: { 113 $id: _id 114 _id: "tool/file.MkdirTemp" 115 116 // The temporary directory is created in the directory specified by dir. 117 // If dir is the empty string, MkdirTemp uses the default directory for 118 // temporary files. 119 dir: string | *"" 120 121 // The directory name is generated by adding a random string to the end of pattern. 122 // If pattern includes a "*", the random string replaces the last "*" instead. 123 pattern: string | *"" 124 125 // The absolute path of the created directory. 126 path: string 127 } 128 129 // RemoveAll removes path and any children it contains. 130 // It removes everything it can but returns the first error it encounters. 131 RemoveAll: { 132 $id: _id 133 _id: "tool/file.RemoveAll" 134 135 // The path to remove. 136 // If the path does not exist, RemoveAll does nothing. 137 path: string 138 139 // success contains the status of the removal. 140 // If path was removed success is set to true. 141 // If path didn't exists success is set to false. 142 success: bool 143 }