@@ -24,7 +24,7 @@ import (
2424 "gopkg.in/alecthomas/kingpin.v2"
2525)
2626
27- // Module collects several plugin commands underneath a module command and offers the possibility to define CLI flags
27+ // Module consists out of several plugins and offers methods for executing them
2828type Module interface {
2929 Name () string
3030 Description () string
@@ -37,6 +37,7 @@ type Module interface {
3737 GetPluginByName (pluginName string ) (Plugin , error )
3838}
3939
40+ // ModuleOpt is a type alias for functional options used by NewModule()
4041type ModuleOpt func (* baseModule )
4142
4243type baseModule struct {
@@ -45,6 +46,8 @@ type baseModule struct {
4546 plugins map [string ]Plugin
4647}
4748
49+ // RegisterModules returns a map of modules with their name as the respective key. Additionally, all plugins contained
50+ // by these modules are being registered to their respective module using Plugin.setModule()
4851func RegisterModules (modules ... Module ) map [string ]Module {
4952 result := make (map [string ]Module )
5053 for _ , module := range modules {
@@ -57,7 +60,7 @@ func RegisterModules(modules ...Module) map[string]Module {
5760 return result
5861}
5962
60- // NewModule instantiates a new baseModule, which should be inherited by user-defined module types
63+ // NewModule instantiates baseModule with the given functional options
6164func NewModule (name string , options ... ModuleOpt ) Module {
6265 module := & baseModule {
6366 name : name ,
@@ -72,12 +75,14 @@ func NewModule(name string, options ...ModuleOpt) Module {
7275 return module
7376}
7477
78+ // ModuleDescription is a functional option for NewModule(), which sets the module description
7579func ModuleDescription (description string ) ModuleOpt {
7680 return func (m * baseModule ) {
7781 m .description = description
7882 }
7983}
8084
85+ // ModulePlugin is a functional option for NewModule(), which registers a plugin using Module.RegisterPlugin()
8186func ModulePlugin (plugin Plugin ) ModuleOpt {
8287 return func (m * baseModule ) {
8388 m .RegisterPlugin (plugin )
0 commit comments