Pndpd/main.go

67 lines
1.4 KiB
Go
Raw Normal View History

2021-12-20 14:53:42 -05:00
package main
import (
"fmt"
"os"
"os/signal"
2021-12-25 09:28:59 -05:00
"pndpd/modules"
"syscall"
2021-12-20 14:53:42 -05:00
)
2021-12-28 06:19:19 -05:00
import (
// Modules
_ "pndpd/modules/example"
_ "pndpd/modules/userInterface"
)
2021-12-20 14:53:42 -05:00
// waitForSignal Waits (blocking) for the program to be interrupted by the OS
func waitForSignal() {
2021-12-27 06:37:08 -05:00
var sigCh = make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
<-sigCh
close(sigCh)
}
2021-12-20 14:53:42 -05:00
func main() {
fmt.Println("PNDPD Version 1.2.1 - Kioubit 2021")
2021-12-20 16:46:26 -05:00
2021-12-22 06:04:00 -05:00
if len(os.Args) <= 2 {
printUsage()
return
2021-12-20 14:53:42 -05:00
}
2021-12-22 06:04:00 -05:00
switch os.Args[1] {
case "config":
2021-12-21 06:42:30 -05:00
readConfig(os.Args[2])
2021-12-22 06:04:00 -05:00
default:
2021-12-28 06:19:19 -05:00
module, command := modules.GetCommand(os.Args[1], modules.CommandLine)
if module != nil {
modules.ExecuteInit(module, modules.CallbackInfo{
CallbackType: modules.CommandLine,
Command: command,
Arguments: os.Args[2:],
})
if modules.ExistsBlockingModule() {
modules.ExecuteComplete()
waitForSignal()
modules.ShutdownAll()
2021-12-25 09:28:59 -05:00
}
} else {
printUsage()
2021-12-25 09:28:59 -05:00
}
2021-12-21 06:00:28 -05:00
}
2021-12-22 06:04:00 -05:00
}
2021-12-20 16:46:26 -05:00
2021-12-22 06:04:00 -05:00
func printUsage() {
2021-12-25 13:03:11 -05:00
fmt.Println("More options and additional documentation in the example config file")
fmt.Println("Usage:")
fmt.Println("pndpd config <path to file>")
2021-12-25 13:03:11 -05:00
for i := range modules.ModuleList {
for d := range (*modules.ModuleList[i]).Commands {
2021-12-28 06:19:19 -05:00
if (*modules.ModuleList[i]).Commands[d].CommandLineEnabled {
fmt.Println("pndpd", (*modules.ModuleList[i]).Commands[d].Description)
}
2021-12-25 13:03:11 -05:00
}
}
2021-12-20 14:53:42 -05:00
}