Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dtm develop create-plugin enhancement #456

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/pkg/develop/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func (p *Plugin) renderTplString(tplStr string) (string, error) {
return "", nil
}

t, err := template.New("default").Parse(tplStr)
var funcMap = template.FuncMap{
"format": pluginTpl.FormatPackageName,
}

t, err := template.New("default").Funcs(funcMap).Parse(tplStr)
if err != nil {
log.Debugf("Template parse failed: %s.", err)
log.Debugf("Template content: %s.", tplStr)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/NAME.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package template
var NAME_go_nameTpl = "{{ .Name }}.go"
var NAME_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var NAME_go_mustExistFlag = true
var NAME_go_contentTpl = `package {{ .Name }}
var NAME_go_contentTpl = `package {{ .Name | format }}

// TODO(dtm): Add your logic here.
`
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var create_go_nameTpl = "create.go"
var create_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var create_go_contentTpl = `package {{ .Name }}
var create_go_contentTpl = `package {{ .Name | format }}

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var delete_go_nameTpl = "delete.go"
var delete_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var delete_go_contentTpl = `package {{ .Name }}
var delete_go_contentTpl = `package {{ .Name | format }}

import (
"fmt"
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/develop/plugin/template/funcmaps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package template

import "strings"

func FormatPackageName(name string) string {
return strings.ReplaceAll(name, "-", "")
}
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var options_go_nameTpl = "options.go"
var options_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var options_go_contentTpl = `package {{ .Name }}
var options_go_contentTpl = `package {{ .Name | format }}

// Options is the struct for configurations of the {{ .Name }} plugin.
type Options struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var read_go_nameTpl = "read.go"
var read_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var read_go_contentTpl = `package {{ .Name }}
var read_go_contentTpl = `package {{ .Name | format }}

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var update_go_nameTpl = "update.go"
var update_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var update_go_contentTpl = `package {{ .Name }}
var update_go_contentTpl = `package {{ .Name | format }}

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/develop/plugin/template/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package template

var validate_go_nameTpl = "validate.go"
var validate_go_dirTpl = "internal/pkg/plugin/{{ .Name }}/"
var validate_go_contentTpl = `package {{ .Name }}
var validate_go_contentTpl = `package {{ .Name | format }}

// validate validates the options provided by the core.
func validate(options *Options) []error {
Expand Down