Pndpd/modules/example/example.go

53 lines
1.4 KiB
Go
Raw Normal View History

2021-12-28 06:19:19 -05:00
//go:build mod_example
// +build mod_example
2021-12-25 09:28:59 -05:00
package example
import (
"fmt"
"pndpd/modules"
)
2021-12-28 06:19:19 -05:00
// This is an example module
2021-12-25 09:28:59 -05:00
func init() {
commands := []modules.Command{{
2021-12-28 06:19:19 -05:00
CommandText: "command1",
Description: "This is the usage description for command1",
BlockTerminate: true,
CommandLineEnabled: true,
ConfigEnabled: true,
2021-12-25 13:03:11 -05:00
}, {
2021-12-28 06:19:19 -05:00
CommandText: "command2",
Description: "This is the usage description for command2",
BlockTerminate: false,
CommandLineEnabled: false,
ConfigEnabled: true,
2021-12-25 13:03:11 -05:00
},
2021-12-25 09:28:59 -05:00
}
modules.RegisterModule("Example", commands, initCallback, completeCallback, shutdownCallback)
2021-12-25 09:28:59 -05:00
}
func initCallback(callback modules.CallbackInfo) {
2021-12-25 13:03:11 -05:00
if callback.CallbackType == modules.CommandLine {
// The command registered by the module has been run in the commandline
// "arguments" contains the os.Args[] passed to the program after the command registered by this module
fmt.Println("Command: ", callback.Command.CommandText)
2021-12-25 13:03:11 -05:00
fmt.Println(callback.Arguments)
} else {
// The command registered by the module was found in the config file
// "arguments" contains the lines between the curly braces
fmt.Println("Command: ", callback.Command.CommandText)
2021-12-25 13:03:11 -05:00
fmt.Println(callback.Arguments)
2021-12-25 09:28:59 -05:00
}
2021-12-25 13:03:11 -05:00
fmt.Println()
2021-12-25 09:28:59 -05:00
}
func completeCallback() {
//Called after the program has passed all options by calls to initCallback()
}
func shutdownCallback() {
fmt.Println("Terminate all work")
}