lang: funcs: funcgen: Clean up some small details

Some small changes were needed, here they are. Unfortunately this only
supports the `string` type at the moment.
This commit is contained in:
James Shubin
2019-02-21 12:58:50 -05:00
parent a0df4829a8
commit 00db953c9f
10 changed files with 19 additions and 16 deletions

2
.gitignore vendored
View File

@@ -8,8 +8,6 @@ tmp/
*WIP
*_stringer.go
bindata/*.go
generated_funcs.go
generated_funcs_test.go
mgmt
mgmt.static
# crossbuild artifacts

View File

@@ -410,11 +410,12 @@ help: ## show this help screen
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ''
funcgen: lang/funcs/core/generated_funcs_tests.go lang/funcs/core/generated_funcs.go
funcgen: lang/funcs/core/generated_funcs_test.go lang/funcs/core/generated_funcs.go
lang/funcs/core/generated_funcs_tests.go: lang/funcs/core/generated_funcs.go
lang/funcs/core/generated_funcs_test.go: lang/funcs/funcgen/*.go lang/funcs/core/funcgen.yaml lang/funcs/funcgen/templates/generated_funcs_test.go.tpl
go run lang/funcs/funcgen/*.go -templates lang/funcs/funcgen/templates/generated_funcs_test.go.tpl
lang/funcs/core/generated_funcs.go: lang/golang2mgmt/*.go lang/funcs/core/golang2mgmt.yaml lang/golang2mgmt/templates/*.tpl
go run lang/golang2mgmt/*.go
lang/funcs/core/generated_funcs.go: lang/funcs/funcgen/*.go lang/funcs/core/funcgen.yaml lang/funcs/funcgen/templates/generated_funcs.go.tpl
go run lang/funcs/funcgen/*.go -templates lang/funcs/funcgen/templates/generated_funcs.go.tpl
# vim: ts=8

2
lang/funcs/core/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
generated_funcs.go
generated_funcs_test.go

View File

@@ -1,5 +1,5 @@
# This file is to be used by github.com/purpleidea/mgmt/lang/golang2mgmt
# to generate mgmt functions
# This file is used by github.com/purpleidea/mgmt/lang/funcs/funcgen/ to
# generate mcl functions.
functions:
- mgmtName: to_upper
mgmtPackage: strings
@@ -15,7 +15,7 @@ functions:
return: [{type: string, value: "HELLO 22"}]
- mgmtName: trim
mgmtPackage: strings
help: returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed..
help: returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
goPackage: strings
goFunc: Trim
args: [{name: s, type: string}, {name: cutset, type: string}]

View File

@@ -19,6 +19,8 @@ package main
import (
"fmt"
"github.com/purpleidea/mgmt/lang/types"
)
type config struct {
@@ -44,7 +46,7 @@ func (obj *arg) ToMcl() (string, error) {
if obj.Name != "" {
return fmt.Sprintf("%s str", obj.Name), nil
}
return "str", nil
return types.TypeStr.String(), nil
}
return "", fmt.Errorf("cannot convert %v to mcl", obj)
}

View File

@@ -54,7 +54,7 @@ func parseFuncs(c config, path, templates string) error {
return err
}
for _, tpl := range templateFiles {
log.Printf("Generating %s", tpl)
log.Printf("Template: %s", tpl)
err = generateTemplate(c, path, tpl)
if err != nil {
return err
@@ -64,7 +64,7 @@ func parseFuncs(c config, path, templates string) error {
}
func generateTemplate(c config, path, templateFile string) error {
log.Printf("Reading %s", templateFile)
log.Printf("Reading: %s", templateFile)
basename := filepath.Base(templateFile)
tplFile, err := ioutil.ReadFile(templateFile)
if err != nil {
@@ -76,7 +76,7 @@ func generateTemplate(c config, path, templateFile string) error {
}
finalName := strings.TrimSuffix(basename, ".tpl")
finalPath := filepath.Join(path, finalName)
log.Printf("Writing %s", finalPath)
log.Printf("Writing: %s", finalPath)
finalFile, err := os.Create(finalPath)
if err != nil {
return err

View File

@@ -24,8 +24,8 @@ import (
var (
pkg = flag.String("package", "lang/funcs/core", "path to the package")
filename = flag.String("filename", "golang2mgmt.yaml", "path to the config")
templates = flag.String("templates", "lang/golang2mgmt/templates/*.tpl", "path to the templates")
filename = flag.String("filename", "funcgen.yaml", "path to the config")
templates = flag.String("templates", "lang/funcs/funcgen/templates/*.tpl", "path to the templates")
)
func main() {

View File

@@ -28,7 +28,7 @@ import (
func parsePkg(path, filename, templates string) error {
var c config
filePath := filepath.Join(path, filename)
log.Printf("Reading %s", filePath)
log.Printf("Data: %s", filePath)
cfgFile, err := ioutil.ReadFile(filePath)
if err != nil {
return err