Manager: add -write-config
CLI option to create config file and quit
This commit is contained in:
parent
3f081d8c7b
commit
50cc1e64d0
@ -38,6 +38,7 @@ import (
|
||||
|
||||
var cliArgs struct {
|
||||
version bool
|
||||
writeConfig bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -66,6 +67,15 @@ func main() {
|
||||
log.Error().Err(err).Msg("loading configuration")
|
||||
}
|
||||
|
||||
if cliArgs.writeConfig {
|
||||
err := configService.Save()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not write configuration file")
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: enable TLS via Let's Encrypt.
|
||||
listen := configService.Get().Listen
|
||||
_, port, _ := net.SplitHostPort(listen)
|
||||
@ -235,6 +245,8 @@ func parseCliArgs() {
|
||||
flag.BoolVar(&quiet, "quiet", false, "Only log warning-level and worse.")
|
||||
flag.BoolVar(&debug, "debug", false, "Enable debug-level logging.")
|
||||
flag.BoolVar(&trace, "trace", false, "Enable trace-level logging.")
|
||||
flag.BoolVar(&cliArgs.writeConfig, "write-config", false, "Writes configuration to flamenco-manager.yaml, then exits.")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
var logLevel zerolog.Level
|
||||
|
@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/rs/zerolog/log"
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Service provides access to Flamenco Manager configuration.
|
||||
@ -29,3 +31,15 @@ func (s *Service) ExpandVariables(valueToExpand string, audience VariableAudienc
|
||||
func (s *Service) Get() *Conf {
|
||||
return &s.config
|
||||
}
|
||||
|
||||
// Save writes the in-memory configuration to the config file.
|
||||
func (s *Service) Save() error {
|
||||
err := s.config.Write(configFilename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Do the logging here, as our caller doesn't know `configFilename``.
|
||||
log.Info().Str("filename", configFilename).Msg("configuration file written")
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user