argparse/example/main.go
2020-02-12 09:39:46 +00:00

38 lines
673 B
Go

package main
import (
"fmt"
"git.trj.tw/golang/argparse"
)
func main() {
fmt.Println("argparse example")
opts := []string{
"-f", "/config.yml",
"-v",
"--port", "3000",
"--float", "1.23",
"-n", "name!!",
}
p := argparse.New()
var configPath string
var versionFlag bool
var port int
var floatVal float64
var name *string
p.BoolVar(&versionFlag, "v", "version")
p.StringVar(&configPath, "f", "config")
p.IntVar(&port, "p", "port")
p.FloatVar(&floatVal, "ff", "float")
name = p.String("n", "name")
p.Parse(opts)
fmt.Printf("Config: %s\nVersionFlag: %v\nPort: %d\nFloatVal: %f\nName: %s\n", configPath, versionFlag, port, floatVal, *name)
}