github.com/safing/portbase@v0.19.5/info/module/flags.go (about) 1 package module 2 3 import ( 4 "flag" 5 "fmt" 6 7 "github.com/safing/portbase/info" 8 "github.com/safing/portbase/modules" 9 ) 10 11 var showVersion bool 12 13 func init() { 14 modules.Register("info", prep, nil, nil) 15 16 flag.BoolVar(&showVersion, "version", false, "show version and exit") 17 } 18 19 func prep() error { 20 err := info.CheckVersion() 21 if err != nil { 22 return err 23 } 24 25 if printVersion() { 26 return modules.ErrCleanExit 27 } 28 return nil 29 } 30 31 // printVersion prints the version, if requested, and returns if it did so. 32 func printVersion() (printed bool) { 33 if showVersion { 34 fmt.Println(info.FullVersion()) 35 return true 36 } 37 return false 38 }