You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Victorique/vtqe/tools/generate.go

54 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package tools
import (
"fmt"
"os"
"time"
"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")
cap, _ := this.Flags().GetInt("cap")
if len(args) != 1 {
this.Help()
return
}
if num <= 0 {
fmt.Println("num不合法不应该小于1")
os.Exit(2)
}
if sum <= 0 {
fmt.Println("sum不合法不应该小于1")
os.Exit(2)
}
if cap <= 0 {
fmt.Println("cap不合法不应该小于1")
os.Exit(2)
}
err := starainrt.FillWithRandom(args[0], num, cap, sum, func(pect float64) {
fmt.Printf("文件已处理:%f%%\r", pect)
})
if err != nil {
fmt.Println("err:" + err.Error())
}
fmt.Println("文件已处理100.0000000%")
time.Sleep(time.Millisecond * 10)
},
}
func init() {
gencmd.Flags().IntP("sum", "s", 3, "随机的种子组数")
gencmd.Flags().IntP("num", "n", 1024, "生成的文件大小")
gencmd.Flags().IntP("cap", "c", 1048576, "bufcap大小")
gencmd.MarkFlagRequired("num")
Maincmd.AddCommand(gencmd)
}