feature: #175 Print verison with --version
This commit is contained in:
parent
d639a802dc
commit
50204f8180
|
|
@ -31,27 +31,52 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
initLog()
|
||||||
|
|
||||||
|
initViperConfig(initCliFlags())
|
||||||
|
|
||||||
|
initCheckEnvironment()
|
||||||
|
|
||||||
|
initInstallationInfo()
|
||||||
|
|
||||||
|
log.Info("OliveTin initialization complete")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initLog() {
|
||||||
log.SetFormatter(&log.TextFormatter{
|
log.SetFormatter(&log.TextFormatter{
|
||||||
ForceQuote: true,
|
ForceQuote: true,
|
||||||
DisableTimestamp: true,
|
DisableTimestamp: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
// Use debug this early on to catch details about startup errors. The
|
||||||
"version": version,
|
// default config will raise the log level later, if not set.
|
||||||
"commit": commit,
|
log.SetLevel(log.DebugLevel) // Default to debug, to catch cfg issue
|
||||||
"date": date,
|
}
|
||||||
}).Info("OliveTin initializing")
|
|
||||||
|
|
||||||
log.SetLevel(log.DebugLevel) // Default to debug, to catch cfg issues
|
|
||||||
|
|
||||||
|
func initCliFlags() string {
|
||||||
var configDir string
|
var configDir string
|
||||||
flag.StringVar(&configDir, "configdir", ".", "Config directory path")
|
flag.StringVar(&configDir, "configdir", ".", "Config directory path")
|
||||||
|
|
||||||
|
var printVersion bool
|
||||||
|
flag.BoolVar(&printVersion, "version", false, "Prints the version number and exits")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// This log message should be the first log message OliveTin prints.
|
||||||
|
if printVersion {
|
||||||
|
logStartupMessage("OliveTin is just printing the startup message")
|
||||||
|
os.Exit(1)
|
||||||
|
} else {
|
||||||
|
logStartupMessage("OliveTin initializing")
|
||||||
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"value": configDir,
|
"value": configDir,
|
||||||
}).Debugf("Value of -configdir flag")
|
}).Debugf("Value of -configdir flag")
|
||||||
|
|
||||||
|
return configDir
|
||||||
|
}
|
||||||
|
|
||||||
|
func initViperConfig(configDir string) {
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.SetConfigName("config.yaml")
|
viper.SetConfigName("config.yaml")
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
|
|
@ -76,15 +101,25 @@ func init() {
|
||||||
})
|
})
|
||||||
|
|
||||||
reloadConfig()
|
reloadConfig()
|
||||||
|
}
|
||||||
|
|
||||||
warnIfPuidGuid()
|
func initInstallationInfo() {
|
||||||
|
|
||||||
installationinfo.Config = cfg
|
installationinfo.Config = cfg
|
||||||
installationinfo.Build.Version = version
|
installationinfo.Build.Version = version
|
||||||
installationinfo.Build.Commit = commit
|
installationinfo.Build.Commit = commit
|
||||||
installationinfo.Build.Date = date
|
installationinfo.Build.Date = date
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("Init complete")
|
func logStartupMessage(message string) {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"version": version,
|
||||||
|
"commit": commit,
|
||||||
|
"date": date,
|
||||||
|
}).Info(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initCheckEnvironment() {
|
||||||
|
warnIfPuidGuid()
|
||||||
}
|
}
|
||||||
|
|
||||||
func warnIfPuidGuid() {
|
func warnIfPuidGuid() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue