Pndpd/modules/example/example.go

36 lines
1005 B
Go
Raw Normal View History

2021-12-25 09:28:59 -05:00
package example
import (
"fmt"
"pndpd/modules"
)
// This is an example module that is not imported by the main program
func init() {
2021-12-25 13:03:11 -05:00
option := []modules.Option{{
Option: "command1",
Description: "This is the usage description for command1",
}, {
Option: "command2",
Description: "This is the usage description for command2",
},
2021-12-25 09:28:59 -05:00
}
2021-12-25 13:03:11 -05:00
modules.RegisterModule("Example", option, callback)
2021-12-25 09:28:59 -05:00
}
2021-12-25 13:03:11 -05:00
func callback(callback modules.Callback) {
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.Option)
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.Option)
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
}