github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/internal/sh/builtin/loader.go (about) 1 package builtin 2 3 import ( 4 "io" 5 6 "github.com/madlambda/nash/sh" 7 ) 8 9 // Fn is the contract of a built in function, that is simpler 10 // than the core nash Fn. 11 type ( 12 Fn interface { 13 ArgNames() []sh.FnArg 14 SetArgs(args []sh.Obj) error 15 Run( 16 stdin io.Reader, 17 stdout io.Writer, 18 stderr io.Writer, 19 ) ([]sh.Obj, error) 20 } 21 22 Constructor func() Fn 23 ) 24 25 // Constructors returns a map of the builtin function name and its constructor 26 func Constructors() map[string]Constructor { 27 return map[string]Constructor{ 28 "glob": func() Fn { return newGlob() }, 29 "print": func() Fn { return newPrint() }, 30 "format": func() Fn { return newFormat() }, 31 "split": func() Fn { return newSplit() }, 32 "len": func() Fn { return newLen() }, 33 "chdir": func() Fn { return newChdir() }, 34 "append": func() Fn { return newAppend() }, 35 "exit": func() Fn { return newExit() }, 36 } 37 }