Skip to content

flag: Set stops parsing arguments when encountering an unknown flag even in ContinueOnError mode #70167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
libmonsoon-dev opened this issue Nov 2, 2024 · 6 comments

Comments

@libmonsoon-dev
Copy link

libmonsoon-dev commented Nov 2, 2024

Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/daniil_stepanenko/.cache/go-build'
GOENV='/home/daniil_stepanenko/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/daniil_stepanenko/go/pkg/mod'
GOOS='linux'
GOPATH='/home/daniil_stepanenko/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/daniil_stepanenko/go/go1.23.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/daniil_stepanenko/go/go1.23.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/daniil_stepanenko/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/daniil_stepanenko/work/upstream/gomplate/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2364282043=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to make a package that will contain public variables based on the command line arguments of the process that imported the package. This could be useful in many places, but at the moment I want to know if the -test.v flag is set and the coverage settings

https://go.dev/play/p/b87bzeDhaFO

What did you see happen?

flag provided but not defined: -notdefined
false

Program exited.

What did you expect to see?

The err variable contains a value that can be processed not through strings.Contains but in a more correct way through errors.As/Is
And most importantly, the Verbose variable is set to true

@libmonsoon-dev
Copy link
Author

The problem with extra output was solved using fSet.SetOutput(io.Discard)

@seankhliao
Copy link
Member

As the docs for ContinueOnError states, it only controls if flag parsing returns an error or exits the program. In general flag cannot continue since it doesn't know if ia flag is a boolean type.

Closing as working as intended.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2024
@libmonsoon-dev
Copy link
Author

In my opinion, adding a check to see if the next argument (if there is one) is a flag or not is not a big problem.

@libmonsoon-dev
Copy link
Author

Does it make sense to reopen this same thing as a proposal?

@libmonsoon-dev
Copy link
Author

#70168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants