2021-12-20 14:53:42 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-12-24 11:19:36 -05:00
|
|
|
"os/signal"
|
2021-12-25 09:28:59 -05:00
|
|
|
"pndpd/modules"
|
2021-12-24 11:19:36 -05:00
|
|
|
"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
|
|
|
|
2021-12-28 07:26:42 -05:00
|
|
|
var Version = "Development"
|
2021-12-24 11:19:36 -05:00
|
|
|
|
2021-12-20 14:53:42 -05:00
|
|
|
func main() {
|
2022-01-09 08:32:25 -05:00
|
|
|
fmt.Println("PNDPD Version", Version, "- Kioubit 2022")
|
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-27 11:24:21 -05:00
|
|
|
|
2021-12-22 06:04:00 -05:00
|
|
|
switch os.Args[1] {
|
2021-12-24 11:19:36 -05:00
|
|
|
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)
|
2021-12-27 11:24:21 -05:00
|
|
|
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
|
|
|
}
|
2021-12-27 11:24:21 -05:00
|
|
|
} else {
|
|
|
|
printUsage()
|
2021-12-25 09:28:59 -05:00
|
|
|
}
|
2021-12-21 06:00:28 -05:00
|
|
|
}
|
2021-12-24 11:19:36 -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")
|
2021-12-24 11:19:36 -05:00
|
|
|
fmt.Println("Usage:")
|
|
|
|
fmt.Println("pndpd config <path to file>")
|
2021-12-25 13:03:11 -05:00
|
|
|
for i := range modules.ModuleList {
|
2021-12-27 11:24:21 -05:00
|
|
|
for d := range (*modules.ModuleList[i]).Commands {
|
2021-12-28 06:19:19 -05:00
|
|
|
if (*modules.ModuleList[i]).Commands[d].CommandLineEnabled {
|
2022-01-09 08:32:25 -05:00
|
|
|
fmt.Println((*modules.ModuleList[i]).Commands[d].Description)
|
2021-12-28 06:19:19 -05:00
|
|
|
}
|
2021-12-25 13:03:11 -05:00
|
|
|
}
|
|
|
|
}
|
2021-12-20 14:53:42 -05:00
|
|
|
}
|
2021-12-28 07:26:42 -05:00
|
|
|
|
|
|
|
// waitForSignal Waits (blocking) for the program to be interrupted by the OS
|
|
|
|
func waitForSignal() {
|
|
|
|
var sigCh = make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
|
|
|
<-sigCh
|
|
|
|
close(sigCh)
|
|
|
|
}
|