Add cmd line util for modules

This commit is contained in:
Daniel 2021-01-19 15:36:53 +01:00
parent d3e3f1cc3f
commit 9429a3261e
2 changed files with 20 additions and 0 deletions

10
modules/cmd.go Normal file
View file

@ -0,0 +1,10 @@
package modules
var (
cmdLineOperation func() error
)
// SetCmdLineOperation sets a command line operation to be executed instead of starting the system. This is useful when functions need all modules to be prepared for a special operation.
func SetCmdLineOperation(fn func() error) {
cmdLineOperation = fn
}

View file

@ -74,6 +74,16 @@ func Start() error {
return err
}
// execute command if available
if cmdLineOperation != nil {
err := cmdLineOperation()
if err != nil {
SetExitStatusCode(1)
fmt.Fprintf(os.Stderr, "cmdline operation failed: %s\n", err)
}
return ErrCleanExit
}
// start logging
log.EnableScheduling()
err = log.Start()