Skip to content

Instantly share code, notes, and snippets.

@nnzv
Created January 1, 2023 22:34
Show Gist options
  • Save nnzv/2ec69f83d8c79dd6db149698ba3fc578 to your computer and use it in GitHub Desktop.
Save nnzv/2ec69f83d8c79dd6db149698ba3fc578 to your computer and use it in GitHub Desktop.
[Go] Simple usage of flag package
package main
import (
"fmt"
f "flag"
)
var Flag = func() string {
var used string
f.Visit(func(fg *f.Flag) {
used = fg.Name
})
return used
}
func init() {
f.Bool(
"v", false,
"Print the version",
)
f.Parse()
}
func main() {
switch Flag() {
case "v":
fmt.Println("0.1.0")
default:
f.Usage()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment