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:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,8 +8,6 @@ tmp/
|
|||||||
*WIP
|
*WIP
|
||||||
*_stringer.go
|
*_stringer.go
|
||||||
bindata/*.go
|
bindata/*.go
|
||||||
generated_funcs.go
|
|
||||||
generated_funcs_test.go
|
|
||||||
mgmt
|
mgmt
|
||||||
mgmt.static
|
mgmt.static
|
||||||
# crossbuild artifacts
|
# crossbuild artifacts
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -410,11 +410,12 @@ help: ## show this help screen
|
|||||||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||||
@echo ''
|
@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
|
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/golang2mgmt/*.go
|
go run lang/funcs/funcgen/*.go -templates lang/funcs/funcgen/templates/generated_funcs.go.tpl
|
||||||
|
|
||||||
# vim: ts=8
|
# vim: ts=8
|
||||||
|
|||||||
2
lang/funcs/core/.gitignore
vendored
Normal file
2
lang/funcs/core/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
generated_funcs.go
|
||||||
|
generated_funcs_test.go
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# This file is to be used by github.com/purpleidea/mgmt/lang/golang2mgmt
|
# This file is used by github.com/purpleidea/mgmt/lang/funcs/funcgen/ to
|
||||||
# to generate mgmt functions
|
# generate mcl functions.
|
||||||
functions:
|
functions:
|
||||||
- mgmtName: to_upper
|
- mgmtName: to_upper
|
||||||
mgmtPackage: strings
|
mgmtPackage: strings
|
||||||
@@ -15,7 +15,7 @@ functions:
|
|||||||
return: [{type: string, value: "HELLO 22"}]
|
return: [{type: string, value: "HELLO 22"}]
|
||||||
- mgmtName: trim
|
- mgmtName: trim
|
||||||
mgmtPackage: strings
|
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
|
goPackage: strings
|
||||||
goFunc: Trim
|
goFunc: Trim
|
||||||
args: [{name: s, type: string}, {name: cutset, type: string}]
|
args: [{name: s, type: string}, {name: cutset, type: string}]
|
||||||
@@ -19,6 +19,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
@@ -44,7 +46,7 @@ func (obj *arg) ToMcl() (string, error) {
|
|||||||
if obj.Name != "" {
|
if obj.Name != "" {
|
||||||
return fmt.Sprintf("%s str", obj.Name), nil
|
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)
|
return "", fmt.Errorf("cannot convert %v to mcl", obj)
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ func parseFuncs(c config, path, templates string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, tpl := range templateFiles {
|
for _, tpl := range templateFiles {
|
||||||
log.Printf("Generating %s", tpl)
|
log.Printf("Template: %s", tpl)
|
||||||
err = generateTemplate(c, path, tpl)
|
err = generateTemplate(c, path, tpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -64,7 +64,7 @@ func parseFuncs(c config, path, templates string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateTemplate(c config, path, templateFile string) error {
|
func generateTemplate(c config, path, templateFile string) error {
|
||||||
log.Printf("Reading %s", templateFile)
|
log.Printf("Reading: %s", templateFile)
|
||||||
basename := filepath.Base(templateFile)
|
basename := filepath.Base(templateFile)
|
||||||
tplFile, err := ioutil.ReadFile(templateFile)
|
tplFile, err := ioutil.ReadFile(templateFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,7 +76,7 @@ func generateTemplate(c config, path, templateFile string) error {
|
|||||||
}
|
}
|
||||||
finalName := strings.TrimSuffix(basename, ".tpl")
|
finalName := strings.TrimSuffix(basename, ".tpl")
|
||||||
finalPath := filepath.Join(path, finalName)
|
finalPath := filepath.Join(path, finalName)
|
||||||
log.Printf("Writing %s", finalPath)
|
log.Printf("Writing: %s", finalPath)
|
||||||
finalFile, err := os.Create(finalPath)
|
finalFile, err := os.Create(finalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -24,8 +24,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pkg = flag.String("package", "lang/funcs/core", "path to the package")
|
pkg = flag.String("package", "lang/funcs/core", "path to the package")
|
||||||
filename = flag.String("filename", "golang2mgmt.yaml", "path to the config")
|
filename = flag.String("filename", "funcgen.yaml", "path to the config")
|
||||||
templates = flag.String("templates", "lang/golang2mgmt/templates/*.tpl", "path to the templates")
|
templates = flag.String("templates", "lang/funcs/funcgen/templates/*.tpl", "path to the templates")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
func parsePkg(path, filename, templates string) error {
|
func parsePkg(path, filename, templates string) error {
|
||||||
var c config
|
var c config
|
||||||
filePath := filepath.Join(path, filename)
|
filePath := filepath.Join(path, filename)
|
||||||
log.Printf("Reading %s", filePath)
|
log.Printf("Data: %s", filePath)
|
||||||
cfgFile, err := ioutil.ReadFile(filePath)
|
cfgFile, err := ioutil.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
Reference in New Issue
Block a user