package tools import ( "fmt" "strconv" "b612.me/starainrt" "b612.me/starlog" "github.com/spf13/cobra" ) var splitcmd = &cobra.Command{ Use: "split", Short: "分割文件", Long: "按字节或文件数分割文件", Run: func(this *cobra.Command, args []string) { var src, dst string var num int if len(args) == 3 { src = args[0] dst = args[1] num, _ = strconv.Atoi(args[2]) } else { src, _ = this.Flags().GetString("src") dst, _ = this.Flags().GetString("dst") num, _ = this.Flags().GetInt("num") } if !starainrt.Exists(src) { starlog.Errorln("源文件不存在") this.Help() return } if num == 0 { starlog.Errorln("参数num不合法", "red") this.Help() return } crypto := new(starainrt.StarCrypto) ok, _ := this.Flags().GetBool("byte") err := crypto.SplitFile(src, dst, num, !ok, func(pect float64) { if pect == 100 { fmt.Println("文件已处理:100.000000%") } else { fmt.Printf("文件已处理:%f%%\r", pect) } }) if err != nil { starlog.Errorln(err.Error) } }, } func init() { splitcmd.Flags().StringP("src", "s", "", "源文件地址") splitcmd.Flags().StringP("dst", "d", "./split*.vicque", "目标文件地址,用*替换文件数字") splitcmd.Flags().BoolP("byte", "b", false, "按byte分割") splitcmd.Flags().IntP("num", "n", 0, "分割数/byte数") Maincmd.AddCommand(splitcmd) }