github.com/turingchain2020/turingchain@v1.1.21/cmd/tools/commands/gendapp.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package commands 6 7 import ( 8 "fmt" 9 10 "github.com/turingchain2020/turingchain/cmd/tools/strategy" 11 "github.com/turingchain2020/turingchain/cmd/tools/types" 12 "github.com/spf13/cobra" 13 ) 14 15 //GenDappCmd advance cmd 16 func GenDappCmd() *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: "gendapp", 19 Short: "Auto generate dapp basic code", 20 Run: genDapp, 21 } 22 addGenDappFlag(cmd) 23 return cmd 24 } 25 26 func addGenDappFlag(cmd *cobra.Command) { 27 cmd.Flags().StringP("name", "n", "", "dapp name") 28 cmd.MarkFlagRequired("name") 29 cmd.Flags().StringP("proto", "p", "", "dapp protobuf file path") 30 cmd.MarkFlagRequired("proto") 31 cmd.Flags().StringP("output", "o", "", "go package for output (default github.com/turingchain2020/plugin/plugin/dapp/)") 32 33 } 34 35 func genDapp(cmd *cobra.Command, args []string) { 36 37 dappName, _ := cmd.Flags().GetString("name") 38 outDir, _ := cmd.Flags().GetString("output") 39 propFile, _ := cmd.Flags().GetString("proto") 40 41 s := strategy.New(types.KeyGenDapp) 42 if s == nil { 43 fmt.Println(types.KeyGenDapp, "Not support") 44 return 45 } 46 47 s.SetParam(types.KeyExecutorName, dappName) 48 s.SetParam(types.KeyDappOutDir, outDir) 49 s.SetParam(types.KeyProtobufFile, propFile) 50 s.Run() 51 }