root.go:
func init() { rootCmd.PersistentFlags().BoolVarP(&enableLogging, "log", "l", true, "Logging information") fmt.Println("*************************", enableLogging) } func Execute() { err := rootCmd.Execute() fmt.Println("@@@@@@@@@@@@@@@@@@@@@@@@@", enableLogging) if err != nil { os.Exit(1) } }
zzh@ZZHPC:/zdata/Github/mastering-go-expertise/stats_cli$ go run main.go insert -f d4.txt --log=false ************************* true time=2024-06-23T23:27:37.700+08:00 level=ERROR msg="Invalid value a in line 0 strconv.ParseFloat: parsing \"a\": invalid syntax\n" time=2024-06-23T23:27:37.700+08:00 level=ERROR msg="Invalid value b in line 1 strconv.ParseFloat: parsing \"b\": invalid syntax\n" time=2024-06-23T23:27:37.700+08:00 level=ERROR msg="Invalid value c in line 2 strconv.ParseFloat: parsing \"c\": invalid syntax\n" time=2024-06-23T23:27:37.700+08:00 level=ERROR msg="Invalid value d in line 3 strconv.ParseFloat: parsing \"d\": invalid syntax\n" failed to read at least one value @@@@@@@@@@@@@@@@@@@@@@@@@ false
标签:Execute,27,rootCmd,after,Invalid,parsing,value,go,37.700 From: https://www.cnblogs.com/zhangzhihui/p/18264162