Skip to content

Commit 40f6480

Browse files
Bryan C. Millsdmitshur
Bryan C. Mills
authored andcommitted
[release-branch.go1.18] cmd/go: error out of 'go work use' if no directories are given
Otherwise, the behavior of 'go work use -r' (without arguments) may be surprising. For #51448. Change-Id: I50cf1339591720ec5bd333146b89c9944ce420d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/389855 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 4f80943) Reviewed-on: https://go-review.googlesource.com/c/go/+/389299 Trust: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]>
1 parent 839c0f3 commit 40f6480

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/cmd/go/alldocs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/workcmd/use.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
var cmdUse = &base.Command{
23-
UsageLine: "go work use [-r] [moddirs]",
23+
UsageLine: "go work use [-r] moddirs",
2424
Short: "add modules to workspace file",
2525
Long: `Use provides a command-line interface for adding
2626
directories, optionally recursively, to a go.work file.
@@ -101,6 +101,9 @@ func runUse(ctx context.Context, cmd *base.Command, args []string) {
101101
keepDirs[absDir] = dir
102102
}
103103

104+
if len(args) == 0 {
105+
base.Fatalf("go: 'go work use' requires one or more directory arguments")
106+
}
104107
for _, useDir := range args {
105108
if !*useR {
106109
lookDir(useDir)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# For now, 'go work use' requires arguments.
2+
# (Eventually, we may may it implicitly behave like 'go work use .'.
3+
4+
! go work use
5+
stderr '^go: ''go work use'' requires one or more directory arguments'
6+
7+
! go work use -r
8+
stderr '^go: ''go work use'' requires one or more directory arguments'
9+
10+
-- go.work --
11+
go 1.18

0 commit comments

Comments
 (0)