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

View File

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