package main
import(
"fmt"
"flag"
)
func main(){
var user string
var pwd string
var host string
var port int
// &user为-u后面的参数值
flag.StringVar(&user,"u","","用户名默认为空")
flag.StringVar(&pwd,"pwd","","密码默认为空")
flag.StringVar(&host,"localhost","","主机名默认为localhost")
flag.IntVar(&port,"p",3306,"端口默认为3306")
// 重要操作,必须调用这个方法
flag.Parse()
fmt.Printf("user=%v pwd=%v host=%v port=%v",user,pwd,host,port)
}
go语言中的解析命令行参数
最新推荐文章于 2023-01-27 22:27:54 发布