From 1f6a2d302112faf7d96f82b28800974a58fd4558 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Fri, 24 Sep 2021 00:27:42 +0300 Subject: [PATCH] create: replace vfs with embed This patch must be accepted after https://github.com/golang/go/issues/43854 Closes #631 --- cli/codegen/generate_templates_vfs.go | 42 --------------------------- cli/codegen/static/doc.go | 1 - cli/codegen/static/static.go | 12 -------- cli/create/create.go | 8 ++++- 4 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 cli/codegen/generate_templates_vfs.go delete mode 100644 cli/codegen/static/doc.go delete mode 100644 cli/codegen/static/static.go diff --git a/cli/codegen/generate_templates_vfs.go b/cli/codegen/generate_templates_vfs.go deleted file mode 100644 index f198ef2cb..000000000 --- a/cli/codegen/generate_templates_vfs.go +++ /dev/null @@ -1,42 +0,0 @@ -// +build ignore - -package main - -import ( - "net/http" - - "github.com/apex/log" - "github.com/shurcooL/vfsgen" - "github.com/tarantool/cartridge-cli/cli/codegen/static" -) - -type generateFSOpts struct { - FileSystem http.FileSystem - PackageName string - VariableName string - FileName string -} - -var FSOpts = []generateFSOpts{ - generateFSOpts{ - FileSystem: static.CreateCartridgeTemplateFS, - PackageName: "create", - VariableName: "CreateCartridgeTemplateFS", - FileName: "../../create/create_vfsdata_gen.go", - }, -} - -func main() { - for _, opts := range FSOpts { - err := vfsgen.Generate(opts.FileSystem, vfsgen.Options{ - PackageName: opts.PackageName, - BuildTags: "!dev", - VariableName: opts.VariableName, - Filename: opts.FileName, - }) - - if err != nil { - log.Errorf("Error while generating file system: %s", err) - } - } -} diff --git a/cli/codegen/static/doc.go b/cli/codegen/static/doc.go deleted file mode 100644 index 4a9e036b4..000000000 --- a/cli/codegen/static/doc.go +++ /dev/null @@ -1 +0,0 @@ -package static diff --git a/cli/codegen/static/static.go b/cli/codegen/static/static.go deleted file mode 100644 index 816cf1982..000000000 --- a/cli/codegen/static/static.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build dev - -package static - -//go:generate go run -tags=dev ../generate_templates_vfs.go -o templatexxx.go - -import ( - "net/http" - "path/filepath" -) - -var CreateCartridgeTemplateFS http.FileSystem = http.Dir(filepath.Join("..", "..", "create", "templates", "cartridge")) diff --git a/cli/create/create.go b/cli/create/create.go index bce60e9cb..bef5f6a79 100644 --- a/cli/create/create.go +++ b/cli/create/create.go @@ -1,7 +1,9 @@ package create import ( + "embed" "fmt" + "net/http" "os" "github.com/tarantool/cartridge-cli/cli/common" @@ -13,6 +15,10 @@ import ( "github.com/tarantool/cartridge-cli/cli/create/templates" ) +// TODO: add flag when https://github.com/golang/go/issues/43854 is released. +//go:embed templates/cartridge/* +var createCartridgeTemplateFS embed.FS + // Run creates a project in ctx.Project.Path func Run(ctx *context.Ctx) error { common.CheckRecommendedBinaries("git") @@ -37,7 +43,7 @@ func Run(ctx *context.Ctx) error { if ctx.Create.From == "" { switch ctx.Create.Template { case "cartridge": - ctx.Create.TemplateFS = CreateCartridgeTemplateFS + ctx.Create.TemplateFS = http.FS(createCartridgeTemplateFS) default: return fmt.Errorf("Invalid template name: %s", ctx.Create.Template) }