Skip to content

Commit

Permalink
[release-branch.go1.18] cmd/go: error out of 'go work use' if no dire…
Browse files Browse the repository at this point in the history
…ctories 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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit 4f80943)
Reviewed-on: https://go-review.googlesource.com/c/go/+/389299
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
Bryan C. Mills authored and dmitshur committed Mar 7, 2022
1 parent 839c0f3 commit 40f6480
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/cmd/go/internal/workcmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

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

if len(args) == 0 {
base.Fatalf("go: 'go work use' requires one or more directory arguments")
}
for _, useDir := range args {
if !*useR {
lookDir(useDir)
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/testdata/script/work_use_noargs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# For now, 'go work use' requires arguments.
# (Eventually, we may may it implicitly behave like 'go work use .'.

! go work use
stderr '^go: ''go work use'' requires one or more directory arguments'

! go work use -r
stderr '^go: ''go work use'' requires one or more directory arguments'

-- go.work --
go 1.18

0 comments on commit 40f6480

Please sign in to comment.