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: output message is a little confusing #33642

Closed
dotaheor opened this issue Aug 14, 2019 · 1 comment
Closed

flag: output message is a little confusing #33642

dotaheor opened this issue Aug 14, 2019 · 1 comment

Comments

@dotaheor
Copy link

What version of Go are you using (go version)?

go version go1.13beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import (
	"flag"
	"fmt"
)

var (
	volumeName = flag.String("name", "", "volume name")
	volumeSize = flag.String("size", "", "volume size")
)

func main() {
	flag.Parse()
	fmt.Printf("%d, %d \n\n", flag.NArg(), flag.NFlag())
}

What did you see instead?

$ go run example.go arg -size
2, 0 
$ go run example.go.go -name arg -size
flag needs an argument: -size
Usage of /tmp/go-build476191376/b001/exe/example:
  -name string
    	volume name
  -size string
    	volume size
exit status 2
$ go run example.go.go -name -size arg -size
2, 1 

The output of the second command is a little confusing, I think. What about if a user really expects -size is a normal argument?

@dotaheor
Copy link
Author

sorry, there is a misunderstanding in using the flags.

@golang golang locked and limited conversation to collaborators Aug 13, 2020
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

2 participants