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