package tools import ( "fmt" "b612.me/starainrt" "github.com/spf13/cobra" ) var gencmd = &cobra.Command{ Use: "generate", Short: "生成随机文件", Long: "生成指定大小的随机文件", Run: func(this *cobra.Command, args []string) { sum, _ := this.Flags().GetInt("sum") num, _ := this.Flags().GetInt("num") if len(args) != 1 { this.Help() return } err := starainrt.FillWithRandom(args[0], num, 1024*1024, sum, func(pect float64) { if pect == 100 { fmt.Println("文件已处理:100.000000%") } else { fmt.Printf("文件已处理:%f%%\r", pect) } }) if err != nil { fmt.Println("err:" + err.Error()) } }, } func init() { gencmd.Flags().IntP("sum", "s", 3, "随机的种子组数") gencmd.Flags().IntP("num", "n", 1024, "生成的文件大小") gencmd.MarkFlagRequired("num") Maincmd.AddCommand(gencmd) }