I want to access command line arguments with hyphens for example:
go run user.go -version
or
go run user.go --version
When I executing like this, I received the below error:
flag provided but not defined: -version
Usage of /tmp/go-build354377460/command-line-arguments/_obj/exe/user:
--version string
prints current version and exits
exit status 2
Here is my code:
package main
import (
"flag"
"fmt"
)
func main() {
var version string
flag.StringVar(&version, "-version", "", "prints current version and exits")
// Parse the flags
flag.Parse()
fmt.Println(flag.Args())
}
Any help is greatly appreciated. Thanks in advance.