From 0ff91e03dbb7ed169915b12793cbee9ca9798d4c Mon Sep 17 00:00:00 2001 From: RenKanai Date: Sun, 27 Mar 2022 22:06:22 +0900 Subject: [PATCH] cmd/go: reject list when -find and -export are used together Fixes #51952. Change-Id: If2cfc41d65373ca38cfb7b0396be8988d444eb5e Reviewed-on: https://go-review.googlesource.com/c/go/+/396074 Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: David Chase Reviewed-by: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Dmitri Shuralyov --- src/cmd/go/alldocs.go | 2 ++ src/cmd/go/internal/list/list.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 6b91b53347..0f8433efca 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -925,6 +925,8 @@ // // The -find flag causes list to identify the named packages but not // resolve their dependencies: the Imports and Deps lists will be empty. +// With the -find flag, the -deps, -test and -export commands cannot be +// used. // // The -test flag causes list to report not only the named packages // but also their test binaries (for packages with tests), to convey to diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 7f3090872b..259fa2c857 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -193,6 +193,8 @@ and the BuildID field to the build ID of the compiled package. The -find flag causes list to identify the named packages but not resolve their dependencies: the Imports and Deps lists will be empty. +With the -find flag, the -deps, -test and -export commands cannot be +used. The -test flag causes list to report not only the named packages but also their test binaries (for packages with tests), to convey to @@ -592,6 +594,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) { if *listFind && *listTest { base.Fatalf("go list -test cannot be used with -find") } + if *listFind && *listExport { + base.Fatalf("go list -export cannot be used with -find") + } pkgOpts := load.PackageOpts{ IgnoreImports: *listFind, -- 2.48.1