Skip to content

Commit 3a5865c

Browse files
committed
modfile: rename directory directive to use
For golang/go#48257 Change-Id: I9cbb222c93a066717595bec14ff26f2902ef05d9 Reviewed-on: https://go-review.googlesource.com/c/mod/+/359412 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
1 parent c96bc14 commit 3a5865c

13 files changed

+99
-99
lines changed

modfile/rule.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
609609
f.Go = &Go{Syntax: line}
610610
f.Go.Version = args[0]
611611

612-
case "directory":
612+
case "use":
613613
if len(args) != 1 {
614614
errorf("usage: %s local/dir", verb)
615615
return
@@ -619,7 +619,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
619619
errorf("invalid quoted string: %v", err)
620620
return
621621
}
622-
f.Directory = append(f.Directory, &Directory{
622+
f.Use = append(f.Use, &Use{
623623
Path: s,
624624
Syntax: line,
625625
})

modfile/testdata/work/comment.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// comment
2-
directory x // eol
2+
use x // eol
33

44
// mid comment
55

66
// comment 2
77
// comment 2 line 2
8-
directory y // eoy
8+
use y // eoy
99

1010
// comment 3

modfile/testdata/work/comment.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// comment
2-
directory "x" // eol
2+
use "x" // eol
33
// mid comment
44

55
// comment 2
66
// comment 2 line 2
7-
directory "y" // eoy
7+
use "y" // eoy
88
// comment 3

modfile/testdata/work/directory.golden

-7
This file was deleted.

modfile/testdata/work/directory.in

-7
This file was deleted.

modfile/testdata/work/replace.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
directory abc
1+
use abc
22

33
replace xyz v1.2.3 => /tmp/z
44

modfile/testdata/work/replace.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
directory "abc"
1+
use "abc"
22

33
replace "xyz" v1.2.3 => "/tmp/z"
44

modfile/testdata/work/replace2.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
directory abc
1+
use abc
22

33
replace (
44
xyz v1.2.3 => /tmp/z

modfile/testdata/work/replace2.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
directory "abc"
1+
use "abc"
22

33
replace (
44
"xyz" v1.2.3 => "/tmp/z"

modfile/testdata/work/use.golden

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use ../foo
2+
3+
use (
4+
/bar
5+
6+
baz
7+
)

modfile/testdata/work/use.in

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use "../foo"
2+
3+
use (
4+
"/bar"
5+
6+
"baz"
7+
)

modfile/work.go

+25-25
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import (
1212

1313
// A WorkFile is the parsed, interpreted form of a go.work file.
1414
type WorkFile struct {
15-
Go *Go
16-
Directory []*Directory
17-
Replace []*Replace
15+
Go *Go
16+
Use []*Use
17+
Replace []*Replace
1818

1919
Syntax *FileSyntax
2020
}
2121

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.
2525
ModulePath string // Module path in the comment.
2626
Syntax *Line
2727
}
@@ -67,7 +67,7 @@ func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) {
6767
Err: fmt.Errorf("unknown block type: %s", strings.Join(x.Token, " ")),
6868
})
6969
continue
70-
case "directory", "replace":
70+
case "use", "replace":
7171
for _, l := range x.Line {
7272
f.add(&errs, l, x.Token[0], l.Token, fix)
7373
}
@@ -87,13 +87,13 @@ func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) {
8787
// Cleanup cleans out all the cleared entries.
8888
func (f *WorkFile) Cleanup() {
8989
w := 0
90-
for _, r := range f.Directory {
90+
for _, r := range f.Use {
9191
if r.Path != "" {
92-
f.Directory[w] = r
92+
f.Use[w] = r
9393
w++
9494
}
9595
}
96-
f.Directory = f.Directory[:w]
96+
f.Use = f.Use[:w]
9797

9898
w = 0
9999
for _, r := range f.Replace {
@@ -133,60 +133,60 @@ func (f *WorkFile) AddGoStmt(version string) error {
133133
return nil
134134
}
135135

136-
func (f *WorkFile) AddDirectory(diskPath, modulePath string) error {
136+
func (f *WorkFile) AddUse(diskPath, modulePath string) error {
137137
need := true
138-
for _, d := range f.Directory {
138+
for _, d := range f.Use {
139139
if d.Path == diskPath {
140140
if need {
141141
d.ModulePath = modulePath
142-
f.Syntax.updateLine(d.Syntax, "directory", AutoQuote(diskPath))
142+
f.Syntax.updateLine(d.Syntax, "use", AutoQuote(diskPath))
143143
need = false
144144
} else {
145145
d.Syntax.markRemoved()
146-
*d = Directory{}
146+
*d = Use{}
147147
}
148148
}
149149
}
150150

151151
if need {
152-
f.AddNewDirectory(diskPath, modulePath)
152+
f.AddNewUse(diskPath, modulePath)
153153
}
154154
return nil
155155
}
156156

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})
160160
}
161161

162-
func (f *WorkFile) SetDirectory(dirs []*Directory) {
162+
func (f *WorkFile) SetUse(dirs []*Use) {
163163
need := make(map[string]string)
164164
for _, d := range dirs {
165165
need[d.Path] = d.ModulePath
166166
}
167167

168-
for _, d := range f.Directory {
168+
for _, d := range f.Use {
169169
if modulePath, ok := need[d.Path]; ok {
170170
d.ModulePath = modulePath
171171
} else {
172172
d.Syntax.markRemoved()
173-
*d = Directory{}
173+
*d = Use{}
174174
}
175175
}
176176

177177
// TODO(#45713): Add module path to comment.
178178

179179
for diskPath, modulePath := range need {
180-
f.AddNewDirectory(diskPath, modulePath)
180+
f.AddNewUse(diskPath, modulePath)
181181
}
182182
f.SortBlocks()
183183
}
184184

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 {
187187
if d.Path == path {
188188
d.Syntax.markRemoved()
189-
*d = Directory{}
189+
*d = Use{}
190190
}
191191
}
192192
return nil

0 commit comments

Comments
 (0)