diff --git a/src/cmd/go/internal/cmdflag/flag.go b/src/cmd/go/internal/cmdflag/flag.go index 8abb7e559f5ab5..cf6789bd1a0dd5 100644 --- a/src/cmd/go/internal/cmdflag/flag.go +++ b/src/cmd/go/internal/cmdflag/flag.go @@ -31,7 +31,7 @@ type FlagNotDefinedError struct { } func (e FlagNotDefinedError) Error() string { - return fmt.Sprintf("flag provided but not defined: -%s", e.Name) + return fmt.Sprintf("The flag '-%s' is an unknown flag.", e.Name) } // A NonFlagError indicates an argument that is not a syntactically-valid flag. diff --git a/src/cmd/go/testdata/script/mod_getmode_vendor.txt b/src/cmd/go/testdata/script/mod_getmode_vendor.txt index d3df2078b07283..80f1badeeef871 100644 --- a/src/cmd/go/testdata/script/mod_getmode_vendor.txt +++ b/src/cmd/go/testdata/script/mod_getmode_vendor.txt @@ -13,7 +13,7 @@ stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text[\\/]l ! go list -mod=vendor -m rsc.io/quote@latest stderr 'go list -m: rsc.io/quote@latest: cannot query module due to -mod=vendor' ! go get -mod=vendor -u -stderr 'flag provided but not defined: -mod' +stderr 'The flag ''-mod'' is an unknown flag.' # Since we don't have a complete module graph, 'go list -m' queries # that require the complete graph should fail with a useful error. diff --git a/src/flag/flag.go b/src/flag/flag.go index eb88c1faa8b558..3a0bb15c63f95a 100644 --- a/src/flag/flag.go +++ b/src/flag/flag.go @@ -926,7 +926,7 @@ func (f *FlagSet) parseOne() (bool, error) { f.usage() return false, ErrHelp } - return false, f.failf("flag provided but not defined: -%s", name) + return false, f.failf("The flag '-%s' is an unknown flag.", name) } if fv, ok := flag.Value.(boolFlag); ok && fv.IsBoolFlag() { // special case: doesn't need an arg diff --git a/src/flag/flag_test.go b/src/flag/flag_test.go index 0d9491c02089de..a26cebed5719cc 100644 --- a/src/flag/flag_test.go +++ b/src/flag/flag_test.go @@ -454,7 +454,7 @@ func TestUsageOutput(t *testing.T) { defer func(old []string) { os.Args = old }(os.Args) os.Args = []string{"app", "-i=1", "-unknown"} Parse() - const want = "flag provided but not defined: -i\nUsage of app:\n" + const want = "The flag '-i' is an unknown flag.\nUsage of app:\n" if got := buf.String(); got != want { t.Errorf("output = %q; want %q", got, want) }