import.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cmd
  2. import (
  3. "fmt"
  4. "os"
  5. "xg_fetl/internal/controllers"
  6. "github.com/spf13/cobra"
  7. )
  8. // 定义导入子命令
  9. var importCmd = &cobra.Command{
  10. Use: "imp",
  11. Short: "导入数据模式",
  12. Run: func(cmd *cobra.Command, args []string) {
  13. // 定义参数变量
  14. inputPath, _ := cmd.Flags().GetString("input")
  15. tableName, _ := cmd.Flags().GetString("table")
  16. // 检查参数
  17. if inputPath == "" {
  18. fmt.Println("错误:必须指定文件名或文件目录 (-i)")
  19. cmd.Usage()
  20. os.Exit(1)
  21. }
  22. if tableName == "" {
  23. fmt.Println("错误:必须指定表名 (-t)")
  24. cmd.Usage()
  25. os.Exit(1)
  26. }
  27. // 打印接收到的参数
  28. fmt.Printf("执行模式: 导入\n")
  29. fmt.Printf("输入路径: %s\n", inputPath)
  30. fmt.Printf("表名: %s\n", tableName)
  31. controllers.ImportController(inputPath)
  32. },
  33. }
  34. // 初始化导入子命令的标志
  35. func init() {
  36. importCmd.Flags().StringP("input", "i", "", "输入文件或目录路径")
  37. importCmd.Flags().StringP("table", "t", "", "目标表名 (例如: t1)")
  38. }