github.com/wfusion/gofusion@v1.1.14/config/flag.go (about) 1 package config 2 3 import ( 4 "flag" 5 6 "github.com/spf13/pflag" 7 ) 8 9 var ( 10 debugFlag bool 11 appFlagString string 12 appBizFlagString string 13 customConfigPath []string 14 ) 15 16 func init() { 17 pflag.StringSliceVar(&customConfigPath, "config-file", nil, "specify config file path, e.g. configs/app.yml") 18 pflag.StringVarP(&appFlagString, "app", "", "", "app name") 19 pflag.BoolVarP(&debugFlag, "debug", "", false, 20 "enable debug mode, only works for http and db component now") 21 pflag.StringVarP(&appBizFlagString, "app-config", "", "", "json string for app config") 22 pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true 23 } 24 25 func parseFlags() { 26 if !pflag.Parsed() { 27 pflag.CommandLine.AddGoFlagSet(flag.CommandLine) 28 pflag.Parse() 29 } 30 }