From 13ac84115ddddcaa01dbb84ea86eca3394aa3638 Mon Sep 17 00:00:00 2001 From: 2637309949 <“2637309949@qq.com”> Date: Fri, 6 Aug 2021 09:58:06 +0800 Subject: [PATCH] style: AssetsFileSystem --- cmd/assert/main.go | 30 ------------------------------ cmd/dolphin/main.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 cmd/assert/main.go diff --git a/cmd/assert/main.go b/cmd/assert/main.go deleted file mode 100644 index 4f72e63b..00000000 --- a/cmd/assert/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "log" - "net/http" - "os" - - "github.com/shurcooL/vfsgen" -) - -// Assets contains project assets. -var Assets http.FileSystem = http.Dir("../assets") - -func main() { - if err := os.MkdirAll("../dist", os.ModePerm); err != nil { - if err != nil { - log.Fatalln(err) - } - return - } - err := vfsgen.Generate(Assets, vfsgen.Options{ - Filename: "../dist/assets.go", - PackageName: "dist", - BuildTags: "!dev", - VariableName: "Assets", - }) - if err != nil { - log.Fatalln(err) - } -} diff --git a/cmd/dolphin/main.go b/cmd/dolphin/main.go index 0adb5a16..a9a0df23 100644 --- a/cmd/dolphin/main.go +++ b/cmd/dolphin/main.go @@ -17,6 +17,7 @@ import ( "github.com/2637309949/dolphin/cmd/dolphin/template/dist" "github.com/2637309949/dolphin/cmd/dolphin/utils" "github.com/gin-gonic/gin" + "github.com/shurcooL/vfsgen" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -25,6 +26,9 @@ import ( _ "github.com/go-sql-driver/mysql" // "github.com/lib/pq" init _ "github.com/lib/pq" + // "github.com/mattn/go-sqlite3" init + _ "github.com/mattn/go-sqlite3" + "golang.org/x/sys/unix" "golang.org/x/term" ) @@ -122,6 +126,9 @@ var ( Use: "dolphin", Long: `Code generation tool for golang`, PersistentPreRun: func(cmd *cobra.Command, args []string) { + if cmd.Use == "assert" || cmd.Use == "new" || cmd.Use == "clean" { + return + } InitViper(cmd, args) }, CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, @@ -234,6 +241,27 @@ var ( return nil }, } + assert = &cobra.Command{ + Use: "assert", + Short: "", + RunE: func(_ *cobra.Command, _ []string) error { + if err := os.MkdirAll("../dist", os.ModePerm); err != nil { + if err != nil { + return err + } + } + err := vfsgen.Generate(http.Dir("./"), vfsgen.Options{ + Filename: "../dist/assets.go", + PackageName: "dist", + BuildTags: "!dev", + VariableName: "Assets", + }) + if err != nil { + return err + } + return nil + }, + } ) func main() { @@ -243,6 +271,7 @@ func main() { rootCmd.AddCommand(more) rootCmd.AddCommand(clean) rootCmd.AddCommand(serve) + rootCmd.AddCommand(assert) if err := rootCmd.Execute(); err != nil { logrus.Fatal(err) }