Build tags for modules
This commit is contained in:
parent
ff27eb5141
commit
2e62c0b5d5
@ -37,7 +37,7 @@ func readConfig(dest string) {
|
||||
if strings.HasSuffix(line, "{") {
|
||||
option := strings.TrimSuffix(strings.TrimSpace(line), "{")
|
||||
option = strings.TrimSpace(option)
|
||||
module, command := modules.GetCommand(option)
|
||||
module, command := modules.GetCommand(option, modules.Config)
|
||||
var lines = make([]string, 0)
|
||||
if module != nil {
|
||||
for {
|
||||
|
12
main.go
12
main.go
@ -5,9 +5,13 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"pndpd/modules"
|
||||
_ "pndpd/modules/userInterface"
|
||||
"syscall"
|
||||
)
|
||||
import (
|
||||
// Modules
|
||||
_ "pndpd/modules/example"
|
||||
_ "pndpd/modules/userInterface"
|
||||
)
|
||||
|
||||
// waitForSignal Waits (blocking) for the program to be interrupted by the OS
|
||||
func waitForSignal() {
|
||||
@ -29,7 +33,7 @@ func main() {
|
||||
case "config":
|
||||
readConfig(os.Args[2])
|
||||
default:
|
||||
module, command := modules.GetCommand(os.Args[1])
|
||||
module, command := modules.GetCommand(os.Args[1], modules.CommandLine)
|
||||
if module != nil {
|
||||
modules.ExecuteInit(module, modules.CallbackInfo{
|
||||
CallbackType: modules.CommandLine,
|
||||
@ -54,7 +58,9 @@ func printUsage() {
|
||||
fmt.Println("pndpd config <path to file>")
|
||||
for i := range modules.ModuleList {
|
||||
for d := range (*modules.ModuleList[i]).Commands {
|
||||
fmt.Println("pndpd", (*modules.ModuleList[i]).Commands[d].Description)
|
||||
if (*modules.ModuleList[i]).Commands[d].CommandLineEnabled {
|
||||
fmt.Println("pndpd", (*modules.ModuleList[i]).Commands[d].Description)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build mod_example
|
||||
// +build mod_example
|
||||
|
||||
package example
|
||||
|
||||
import (
|
||||
@ -5,16 +8,20 @@ import (
|
||||
"pndpd/modules"
|
||||
)
|
||||
|
||||
// This is an example module that is not imported by the main program
|
||||
// This is an example module
|
||||
func init() {
|
||||
commands := []modules.Command{{
|
||||
CommandText: "command1",
|
||||
Description: "This is the usage description for command1",
|
||||
BlockTerminate: true,
|
||||
CommandText: "command1",
|
||||
Description: "This is the usage description for command1",
|
||||
BlockTerminate: true,
|
||||
CommandLineEnabled: true,
|
||||
ConfigEnabled: true,
|
||||
}, {
|
||||
CommandText: "command2",
|
||||
Description: "This is the usage description for command2",
|
||||
BlockTerminate: false,
|
||||
CommandText: "command2",
|
||||
Description: "This is the usage description for command2",
|
||||
BlockTerminate: false,
|
||||
CommandLineEnabled: false,
|
||||
ConfigEnabled: true,
|
||||
},
|
||||
}
|
||||
modules.RegisterModule("Example", commands, initCallback, completeCallback, shutdownCallback)
|
||||
|
1
modules/example/module.go
Normal file
1
modules/example/module.go
Normal file
@ -0,0 +1 @@
|
||||
package example
|
@ -11,9 +11,11 @@ type Module struct {
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
CommandText string
|
||||
Description string
|
||||
BlockTerminate bool
|
||||
CommandText string
|
||||
Description string
|
||||
BlockTerminate bool
|
||||
CommandLineEnabled bool
|
||||
ConfigEnabled bool
|
||||
}
|
||||
|
||||
type CallbackType int
|
||||
@ -39,11 +41,17 @@ func RegisterModule(name string, commands []Command, initCallback func(CallbackI
|
||||
})
|
||||
}
|
||||
|
||||
func GetCommand(target string) (*Module, Command) {
|
||||
func GetCommand(target string, scope CallbackType) (*Module, Command) {
|
||||
for i := range ModuleList {
|
||||
for _, command := range ModuleList[i].Commands {
|
||||
if command.CommandText == target {
|
||||
return ModuleList[i], command
|
||||
if scope == CommandLine && command.CommandLineEnabled {
|
||||
return ModuleList[i], command
|
||||
}
|
||||
if scope == Config && command.ConfigEnabled {
|
||||
return ModuleList[i], command
|
||||
}
|
||||
return nil, Command{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
modules/userInterface/module.go
Normal file
1
modules/userInterface/module.go
Normal file
@ -0,0 +1 @@
|
||||
package userInterface
|
@ -1,3 +1,6 @@
|
||||
//go:build !noUserInterface
|
||||
// +build !noUserInterface
|
||||
|
||||
package userInterface
|
||||
|
||||
import (
|
||||
@ -9,17 +12,23 @@ import (
|
||||
|
||||
func init() {
|
||||
commands := []modules.Command{{
|
||||
CommandText: "proxy",
|
||||
Description: "proxy <interface1> <interface2> <optional whitelist of CIDRs separated by a semicolon applied to interface2>",
|
||||
BlockTerminate: true,
|
||||
CommandText: "proxy",
|
||||
Description: "proxy <interface1> <interface2> <optional whitelist of CIDRs separated by a semicolon applied to interface2>",
|
||||
BlockTerminate: true,
|
||||
ConfigEnabled: true,
|
||||
CommandLineEnabled: true,
|
||||
}, {
|
||||
CommandText: "responder",
|
||||
Description: "responder <interface> <optional whitelist of CIDRs separated by a semicolon>",
|
||||
BlockTerminate: true,
|
||||
CommandText: "responder",
|
||||
Description: "responder <interface> <optional whitelist of CIDRs separated by a semicolon>",
|
||||
BlockTerminate: true,
|
||||
ConfigEnabled: true,
|
||||
CommandLineEnabled: true,
|
||||
}, {
|
||||
CommandText: "modules",
|
||||
Description: "modules available - list available modules",
|
||||
BlockTerminate: false,
|
||||
CommandText: "modules",
|
||||
Description: "modules available - list available modules",
|
||||
BlockTerminate: false,
|
||||
ConfigEnabled: false,
|
||||
CommandLineEnabled: true,
|
||||
}}
|
||||
modules.RegisterModule("Core", commands, initCallback, completeCallback, shutdownCallback)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user