github.com/turingchain2020/turingchain@v1.1.21/cmd/tools/commands/importpackage.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  //ImportCmd 导入命令
    16  func ImportCmd() *cobra.Command {
    17  	cmd := &cobra.Command{
    18  		Use:   "import",
    19  		Short: "Import plugin package",
    20  		Run:   importPackage,
    21  	}
    22  	cmd.Flags().StringP("conf", "c", "plugin/plugin.toml", "path of plugin config file")
    23  	cmd.Flags().StringP("path", "p", "plugin", "path of plugin")
    24  	cmd.Flags().StringP("out", "o", "", "output new config file")
    25  	cmd.Flags().StringP("packname", "", "", "project package name")
    26  	return cmd
    27  }
    28  
    29  //import 之前默认做处理
    30  func importPackage(cmd *cobra.Command, args []string) {
    31  	out, _ := cmd.Flags().GetString("out")
    32  	conf, _ := cmd.Flags().GetString("conf")
    33  	path, _ := cmd.Flags().GetString("path")
    34  	packname, _ := cmd.Flags().GetString("packname")
    35  	s := strategy.New(types.KeyUpdateInit)
    36  	if s == nil {
    37  		fmt.Println(types.KeyUpdateInit, "Not support")
    38  		return
    39  	}
    40  	s.SetParam("path", path)
    41  	s.SetParam("packname", packname)
    42  	s.Run()
    43  
    44  	s = strategy.New(types.KeyImportPackage)
    45  	if s == nil {
    46  		fmt.Println(types.KeyImportPackage, "Not support")
    47  		return
    48  	}
    49  	s.SetParam("path", path)
    50  	s.SetParam("packname", packname)
    51  	s.SetParam("conf", conf)
    52  	s.SetParam("out", out)
    53  	s.Run()
    54  }