lang: interfaces, funcs: Implement fmt.Stringer for functions
This adds the requirement that all function implementations provider a String() string method so that these can be used as vertices in the pgraph library. If we eventually move to generics for the pgraph DAG, then this might not matter, but it's not bad that these have names either.
This commit is contained in:
@@ -29,8 +29,13 @@ import (
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// SystemFuncName is the name this function is registered as.
|
||||
SystemFuncName = "system"
|
||||
)
|
||||
|
||||
func init() {
|
||||
funcs.ModuleRegister(ModuleName, "system", func() interfaces.Func { return &SystemFunc{} })
|
||||
funcs.ModuleRegister(ModuleName, SystemFuncName, func() interfaces.Func { return &SystemFunc{} })
|
||||
}
|
||||
|
||||
// SystemFunc runs a string as a shell command, then produces each line from
|
||||
@@ -47,6 +52,12 @@ type SystemFunc struct {
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// String returns a simple name for this function. This is needed so this struct
|
||||
// can satisfy the pgraph.Vertex interface.
|
||||
func (obj *SystemFunc) String() string {
|
||||
return SystemFuncName
|
||||
}
|
||||
|
||||
// ArgGen returns the Nth arg name for this function.
|
||||
func (obj *SystemFunc) ArgGen(index int) (string, error) {
|
||||
seq := []string{"shell_command"}
|
||||
|
||||
Reference in New Issue
Block a user