mirror of https://github.com/golang/go.git
[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 <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 4f8094386c)
Reviewed-on: https://go-review.googlesource.com/c/go/+/389299
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
parent
839c0f3b3e
commit
40f6480db6
|
|
@ -1535,7 +1535,7 @@
|
|||
//
|
||||
// Usage:
|
||||
//
|
||||
// go work use [-r] [moddirs]
|
||||
// go work use [-r] moddirs
|
||||
//
|
||||
// Use provides a command-line interface for adding
|
||||
// directories, optionally recursively, to a go.work file.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue