Skip to content
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

flag: ContinueOnError is not continuing #16469

Closed
curlup opened this issue Jul 22, 2016 · 2 comments
Closed

flag: ContinueOnError is not continuing #16469

curlup opened this issue Jul 22, 2016 · 2 comments

Comments

@curlup
Copy link

curlup commented Jul 22, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go1.4.2 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="~/gocode"
GORACE=""
GOROOT="~/code/go"
GOTOOLDIR="~/code/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?
fs := flag.NewFlagSet("d", flag.ContinueOnError)
boolPtr := fs.Bool("fork", false, "a bool")
_ = fs.Parse([]string{"-unknown", "--fork"})

https://play.golang.org/p/93DWNF-53z

  1. What did you expect to see?
    fork: true because ContinueOnError is used
  2. What did you see instead?
flag provided but not defined: -unknown
Usage of d:
  -fork
        a bool
fork: false

I didn't expect to see Usage though

@martinlindhe
Copy link

martinlindhe commented Jul 22, 2016

flag.ContinueOnError says "Return a descriptive error" [1]
Additionally, the 2nd parameter to fs.Bool() is the default value to use. Since you set it to false, that will be the value of *boolPtr [2]

Finally, it is continuing, as your go playground link demonstrates by printing the last line "fork: false"

1: https://golang.org/src/flag/flag.go?s=6739:6761#L259
2: https://play.golang.org/p/7QJz9r6lo_

@ianlancetaylor
Copy link
Contributor

I think this is working as intended. Certainly we are not going to change the behavior. If you have a specific suggestion for how to improve the docs, please let us know. Closing.

@golang golang locked and limited conversation to collaborators Jul 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants