golang标准库flag库网络样例之实操(二)

package main

import (
    "fmt"
    "flag"
)

func main() {
    namePtr := flag.String("name", "username", "姓名")
    agePtr := flag.Int("age", 18, "年龄")
    musclePtr := flag.Bool("muscle", true, "是否有肌肉")

    var email string
    flag.StringVar(&email, "email", "[email protected]", "邮箱")

    flag.Parse()

    args := flag.Args()
    fmt.Println("name:", *namePtr)
    fmt.Println("age:", *agePtr)
    fmt.Println("muscle:", *musclePtr)
    fmt.Println("email:", email)
    fmt.Println("args:", args)
}

golang标准库flag库网络样例之实操(二)_第1张图片

对结果中的疑问:为何为-muscle赋值的true也出现在了args输出结果中?

你可能感兴趣的:(golang)