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>
// 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)
}
--- /dev/null
+# 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 --