From 00db953c9f2fd9d7084cd3329f506a113c011faa Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 21 Feb 2019 12:58:50 -0500 Subject: [PATCH] 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. --- .gitignore | 2 -- Makefile | 9 +++++---- lang/funcs/core/.gitignore | 2 ++ lang/funcs/core/{golang2mgmt.yaml => funcgen.yaml} | 6 +++--- lang/{golang2mgmt => funcs/funcgen}/config.go | 4 +++- lang/{golang2mgmt => funcs/funcgen}/func.go | 6 +++--- lang/{golang2mgmt => funcs/funcgen}/main.go | 4 ++-- lang/{golang2mgmt => funcs/funcgen}/pkg.go | 2 +- .../funcgen}/templates/generated_funcs.go.tpl | 0 .../funcgen}/templates/generated_funcs_test.go.tpl | 0 10 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 lang/funcs/core/.gitignore rename lang/funcs/core/{golang2mgmt.yaml => funcgen.yaml} (92%) rename lang/{golang2mgmt => funcs/funcgen}/config.go (95%) rename lang/{golang2mgmt => funcs/funcgen}/func.go (97%) rename lang/{golang2mgmt => funcs/funcgen}/main.go (86%) rename lang/{golang2mgmt => funcs/funcgen}/pkg.go (97%) rename lang/{golang2mgmt => funcs/funcgen}/templates/generated_funcs.go.tpl (100%) rename lang/{golang2mgmt => funcs/funcgen}/templates/generated_funcs_test.go.tpl (100%) diff --git a/.gitignore b/.gitignore index 1d71084c..a8bd7ea7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,6 @@ tmp/ *WIP *_stringer.go bindata/*.go -generated_funcs.go -generated_funcs_test.go mgmt mgmt.static # crossbuild artifacts diff --git a/Makefile b/Makefile index 6532ac8f..5df8f031 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/lang/funcs/core/.gitignore b/lang/funcs/core/.gitignore new file mode 100644 index 00000000..508959f8 --- /dev/null +++ b/lang/funcs/core/.gitignore @@ -0,0 +1,2 @@ +generated_funcs.go +generated_funcs_test.go diff --git a/lang/funcs/core/golang2mgmt.yaml b/lang/funcs/core/funcgen.yaml similarity index 92% rename from lang/funcs/core/golang2mgmt.yaml rename to lang/funcs/core/funcgen.yaml index 62cd2e43..1978c4b2 100644 --- a/lang/funcs/core/golang2mgmt.yaml +++ b/lang/funcs/core/funcgen.yaml @@ -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}] diff --git a/lang/golang2mgmt/config.go b/lang/funcs/funcgen/config.go similarity index 95% rename from lang/golang2mgmt/config.go rename to lang/funcs/funcgen/config.go index 2921d4b8..394c7f1f 100644 --- a/lang/golang2mgmt/config.go +++ b/lang/funcs/funcgen/config.go @@ -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) } diff --git a/lang/golang2mgmt/func.go b/lang/funcs/funcgen/func.go similarity index 97% rename from lang/golang2mgmt/func.go rename to lang/funcs/funcgen/func.go index 2c34287e..d66aad8b 100644 --- a/lang/golang2mgmt/func.go +++ b/lang/funcs/funcgen/func.go @@ -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 diff --git a/lang/golang2mgmt/main.go b/lang/funcs/funcgen/main.go similarity index 86% rename from lang/golang2mgmt/main.go rename to lang/funcs/funcgen/main.go index 3973d7e1..50e2a81b 100644 --- a/lang/golang2mgmt/main.go +++ b/lang/funcs/funcgen/main.go @@ -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() { diff --git a/lang/golang2mgmt/pkg.go b/lang/funcs/funcgen/pkg.go similarity index 97% rename from lang/golang2mgmt/pkg.go rename to lang/funcs/funcgen/pkg.go index 1b8c3854..9745e193 100644 --- a/lang/golang2mgmt/pkg.go +++ b/lang/funcs/funcgen/pkg.go @@ -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 diff --git a/lang/golang2mgmt/templates/generated_funcs.go.tpl b/lang/funcs/funcgen/templates/generated_funcs.go.tpl similarity index 100% rename from lang/golang2mgmt/templates/generated_funcs.go.tpl rename to lang/funcs/funcgen/templates/generated_funcs.go.tpl diff --git a/lang/golang2mgmt/templates/generated_funcs_test.go.tpl b/lang/funcs/funcgen/templates/generated_funcs_test.go.tpl similarity index 100% rename from lang/golang2mgmt/templates/generated_funcs_test.go.tpl rename to lang/funcs/funcgen/templates/generated_funcs_test.go.tpl