From c990e506229e62060b88304461e68a74528dbdb6 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 31 Oct 2022 22:00:45 +0100 Subject: [PATCH] with docker template --- pkg/cli/templatecmd/init.go | 18 +++++++++++++++--- .../templatecmd/templates/docker/.drone.yml | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 pkg/cli/templatecmd/templates/docker/.drone.yml diff --git a/pkg/cli/templatecmd/init.go b/pkg/cli/templatecmd/init.go index c7b33fa..0f1923b 100644 --- a/pkg/cli/templatecmd/init.go +++ b/pkg/cli/templatecmd/init.go @@ -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 diff --git a/pkg/cli/templatecmd/templates/docker/.drone.yml b/pkg/cli/templatecmd/templates/docker/.drone.yml new file mode 100644 index 0000000..8440780 --- /dev/null +++ b/pkg/cli/templatecmd/templates/docker/.drone.yml @@ -0,0 +1,4 @@ +kind: template +load: bust_docker_template.yaml +name: [[.Name]] +data: {}