1
0
mirror of https://github.com/golang/go synced 2024-11-07 11:56:17 -07:00

cmd/go: have go work init use the -workfile flag

Change-Id: Idb4795bde699c919222953ec33fa1083798b2000
Reviewed-on: https://go-review.googlesource.com/c/go/+/385654
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Michael Matloob 2022-02-14 12:05:46 -05:00
parent 3d7f836123
commit ecf3b39c2a
2 changed files with 19 additions and 1 deletions

View File

@ -46,7 +46,10 @@ func runInit(ctx context.Context, cmd *base.Command, args []string) {
// make dirs relative to workFile path before adding the paths to
// the directory entries
workFile := filepath.Join(base.Cwd(), "go.work")
workFile := modload.WorkFilePath()
if workFile == "" {
workFile = filepath.Join(base.Cwd(), "go.work")
}
modload.CreateWorkFile(ctx, workFile, args)
}

View File

@ -0,0 +1,15 @@
# Test that the workfile flag is used by go work init.
go work init
exists go.work
go work init -workfile=$GOPATH/src/foo/foo.work
exists foo/foo.work
cd foo/bar
! go work init
stderr 'already exists'
# Create directories to make go.work files in.
-- foo/dummy.txt --
-- foo/bar/dummy.txt --