with docker template
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2022-10-31 22:00:45 +01:00
parent f44ef84c89
commit c990e50622
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
2 changed files with 19 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package templatecmd
import ( import (
"embed" "embed"
"errors" "errors"
"fmt"
"os" "os"
"text/template" "text/template"
@ -12,6 +13,9 @@ import (
//go:embed templates/gobin_default/* //go:embed templates/gobin_default/*
var gobinDefault embed.FS var gobinDefault embed.FS
//go:embed templates/docker/*
var docker embed.FS
func NewInitCmd() *cobra.Command { func NewInitCmd() *cobra.Command {
var ( var (
template string template string
@ -27,7 +31,12 @@ func NewInitCmd() *cobra.Command {
switch template { switch template {
case "gobin_default": case "gobin_default":
if err := initializeTemplate(&gobinDefault, name); err != nil { if err := initializeTemplate(&gobinDefault, "gobin_default", name); err != nil {
return err
}
break
case "docker":
if err := initializeTemplate(&docker, "docker", name); err != nil {
return err return err
} }
break break
@ -48,13 +57,16 @@ func NewInitCmd() *cobra.Command {
return cmd return cmd
} }
func initializeTemplate(t *embed.FS, name string) error { func initializeTemplate(t *embed.FS, path string, name string) error {
tinit := template. tinit := template.
Must( Must(
template. template.
New(""). New("").
Delims("[[", "]]"). Delims("[[", "]]").
ParseFS(t, "templates/gobin_default/*"), ParseFS(
t,
fmt.Sprintf("templates/%s/*", path),
),
) )
type data struct { type data struct {
Name string Name string

View File

@ -0,0 +1,4 @@
kind: template
load: bust_docker_template.yaml
name: [[.Name]]
data: {}