Add --version flag.

Fixes #2
This commit is contained in:
Jim McDonald 2020-11-26 20:35:34 +00:00
parent a0a6d2ffa8
commit 68fb49a21b
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
1 changed files with 16 additions and 5 deletions

21
main.go
View File

@ -89,17 +89,20 @@ func main2() int {
return 1
}
if err := initLogging(); err != nil {
log.Error().Err(err).Msg("Failed to initialise logging")
return 1
}
majordomo, err := initMajordomo(ctx)
if err != nil {
log.Error().Err(err).Msg("Failed to initialise majordomo")
return 1
}
// runCommands will not return if a command is run.
runCommands(ctx, majordomo)
if err := initLogging(); err != nil {
log.Error().Err(err).Msg("Failed to initialise logging")
return 1
}
logModules()
log.Info().Str("version", ReleaseVersion).Msg("Starting vouch")
@ -152,6 +155,7 @@ func fetchConfig() error {
pflag.String("profile-address", "", "Address on which to run Go profile server")
pflag.String("tracing-address", "", "Address to which to send tracing data")
pflag.String("beacon-node-address", "localhost:4000", "Address on which to contact the beacon node")
pflag.Bool("version", false, "show Vouch version and exit")
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
return errors.Wrap(err, "failed to bind pflags to viper")
@ -792,3 +796,10 @@ func selectSubmitterStrategy(ctx context.Context, monitor metrics.Service, eth2C
}
return submitter, nil
}
func runCommands(ctx context.Context, majordomo majordomo.Service) {
if viper.GetBool("version") {
fmt.Printf("%s\n", ReleaseVersion)
os.Exit(0)
}
}