github.com/turingchain2020/turingchain@v1.1.21/cmd/tools/commands/createplugin.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  //CreatePluginCmd 构造插件命令
    16  func CreatePluginCmd() *cobra.Command {
    17  	cmd := &cobra.Command{
    18  		Use:   "createplugin",
    19  		Short: "Create turingchain plugin project mode",
    20  		Run:   createPlugin,
    21  	}
    22  	addCreatePluginFlag(cmd)
    23  	return cmd
    24  }
    25  
    26  func addCreatePluginFlag(cmd *cobra.Command) {
    27  	cmd.Flags().StringP("name", "n", "", "project name")
    28  	cmd.MarkFlagRequired("name")
    29  
    30  }
    31  
    32  func createPlugin(cmd *cobra.Command, args []string) {
    33  	projectName, _ := cmd.Flags().GetString("name")
    34  
    35  	s := strategy.New(types.KeyCreatePlugin)
    36  	if s == nil {
    37  		fmt.Println(types.KeyCreatePlugin, "Not support")
    38  		return
    39  	}
    40  	s.SetParam(types.KeyProjectName, projectName)
    41  	s.SetParam(types.KeyExecutorName, projectName)
    42  	s.SetParam(types.KeyClassName, projectName)
    43  	s.Run()
    44  }