@@ -12,16 +12,16 @@ import (
12
12
13
13
// A WorkFile is the parsed, interpreted form of a go.work file.
14
14
type WorkFile struct {
15
- Go * Go
16
- Directory []* Directory
17
- Replace []* Replace
15
+ Go * Go
16
+ Use []* Use
17
+ Replace []* Replace
18
18
19
19
Syntax * FileSyntax
20
20
}
21
21
22
- // A Directory is a single directory statement.
23
- type Directory struct {
24
- Path string // Directory path of module.
22
+ // A Use is a single directory statement.
23
+ type Use struct {
24
+ Path string // Use path of module.
25
25
ModulePath string // Module path in the comment.
26
26
Syntax * Line
27
27
}
@@ -67,7 +67,7 @@ func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) {
67
67
Err : fmt .Errorf ("unknown block type: %s" , strings .Join (x .Token , " " )),
68
68
})
69
69
continue
70
- case "directory " , "replace" :
70
+ case "use " , "replace" :
71
71
for _ , l := range x .Line {
72
72
f .add (& errs , l , x .Token [0 ], l .Token , fix )
73
73
}
@@ -87,13 +87,13 @@ func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) {
87
87
// Cleanup cleans out all the cleared entries.
88
88
func (f * WorkFile ) Cleanup () {
89
89
w := 0
90
- for _ , r := range f .Directory {
90
+ for _ , r := range f .Use {
91
91
if r .Path != "" {
92
- f .Directory [w ] = r
92
+ f .Use [w ] = r
93
93
w ++
94
94
}
95
95
}
96
- f .Directory = f .Directory [:w ]
96
+ f .Use = f .Use [:w ]
97
97
98
98
w = 0
99
99
for _ , r := range f .Replace {
@@ -133,60 +133,60 @@ func (f *WorkFile) AddGoStmt(version string) error {
133
133
return nil
134
134
}
135
135
136
- func (f * WorkFile ) AddDirectory (diskPath , modulePath string ) error {
136
+ func (f * WorkFile ) AddUse (diskPath , modulePath string ) error {
137
137
need := true
138
- for _ , d := range f .Directory {
138
+ for _ , d := range f .Use {
139
139
if d .Path == diskPath {
140
140
if need {
141
141
d .ModulePath = modulePath
142
- f .Syntax .updateLine (d .Syntax , "directory " , AutoQuote (diskPath ))
142
+ f .Syntax .updateLine (d .Syntax , "use " , AutoQuote (diskPath ))
143
143
need = false
144
144
} else {
145
145
d .Syntax .markRemoved ()
146
- * d = Directory {}
146
+ * d = Use {}
147
147
}
148
148
}
149
149
}
150
150
151
151
if need {
152
- f .AddNewDirectory (diskPath , modulePath )
152
+ f .AddNewUse (diskPath , modulePath )
153
153
}
154
154
return nil
155
155
}
156
156
157
- func (f * WorkFile ) AddNewDirectory (diskPath , modulePath string ) {
158
- line := f .Syntax .addLine (nil , "directory " , AutoQuote (diskPath ))
159
- f .Directory = append (f .Directory , & Directory {Path : diskPath , ModulePath : modulePath , Syntax : line })
157
+ func (f * WorkFile ) AddNewUse (diskPath , modulePath string ) {
158
+ line := f .Syntax .addLine (nil , "use " , AutoQuote (diskPath ))
159
+ f .Use = append (f .Use , & Use {Path : diskPath , ModulePath : modulePath , Syntax : line })
160
160
}
161
161
162
- func (f * WorkFile ) SetDirectory (dirs []* Directory ) {
162
+ func (f * WorkFile ) SetUse (dirs []* Use ) {
163
163
need := make (map [string ]string )
164
164
for _ , d := range dirs {
165
165
need [d .Path ] = d .ModulePath
166
166
}
167
167
168
- for _ , d := range f .Directory {
168
+ for _ , d := range f .Use {
169
169
if modulePath , ok := need [d .Path ]; ok {
170
170
d .ModulePath = modulePath
171
171
} else {
172
172
d .Syntax .markRemoved ()
173
- * d = Directory {}
173
+ * d = Use {}
174
174
}
175
175
}
176
176
177
177
// TODO(#45713): Add module path to comment.
178
178
179
179
for diskPath , modulePath := range need {
180
- f .AddNewDirectory (diskPath , modulePath )
180
+ f .AddNewUse (diskPath , modulePath )
181
181
}
182
182
f .SortBlocks ()
183
183
}
184
184
185
- func (f * WorkFile ) DropDirectory (path string ) error {
186
- for _ , d := range f .Directory {
185
+ func (f * WorkFile ) DropUse (path string ) error {
186
+ for _ , d := range f .Use {
187
187
if d .Path == path {
188
188
d .Syntax .markRemoved ()
189
- * d = Directory {}
189
+ * d = Use {}
190
190
}
191
191
}
192
192
return nil
0 commit comments