mirror of
https://github.com/safing/portbase
synced 2025-04-18 00:19:09 +00:00
Add cmd line util for modules
This commit is contained in:
parent
d3e3f1cc3f
commit
9429a3261e
2 changed files with 20 additions and 0 deletions
10
modules/cmd.go
Normal file
10
modules/cmd.go
Normal 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
|
||||
}
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue