package tools import ( "fmt" "b612.me/starainrt" "b612.me/starlog" "github.com/spf13/cobra" ) var mergecmd = &cobra.Command{ Use: "merge", Short: "合并文件", Long: "按路径自动合并分割的文件", Run: func(this *cobra.Command, args []string) { var src, dst string if len(args) == 2 { src = args[0] dst = args[1] } else { src, _ = this.Flags().GetString("src") dst, _ = this.Flags().GetString("dst") } if src == "" || dst == "" { this.Help() return } crypto := new(starainrt.StarCrypto) err := crypto.MergeFile(src, dst, func(pect float64) { if pect == 100 { fmt.Println("文件已处理:100.000000%") } else { fmt.Printf("文件已处理:%f%%\r", pect) } }) if err != nil { starlog.Println(err.Error, "red", "") } }, } func init() { mergecmd.Flags().StringP("src", "s", "", "源文件地址,用*替换文件数字") mergecmd.Flags().StringP("dst", "d", "", "目标文件地址") Maincmd.AddCommand(mergecmd) }