29 lines
652 B
Go
29 lines
652 B
Go
package cmd
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
verifyCode "archgrid.xyz/ag/toolsbox/random/verify_code"
|
||
"github.com/spf13/cobra"
|
||
)
|
||
|
||
var (
|
||
verifyCodeLength int
|
||
)
|
||
|
||
var verifyCodeCmd = &cobra.Command{
|
||
Use: "verify_code",
|
||
Short: "生成指定长度的随机验证码",
|
||
Run: verifyCodeExecute,
|
||
}
|
||
|
||
func verifyCodeExecute(cmd *cobra.Command, args []string) {
|
||
code := verifyCode.RandStr(verifyCodeLength)
|
||
fmt.Printf("生成的验证码为:%s\n", code)
|
||
}
|
||
|
||
func init() {
|
||
verifyCodeCmd.PersistentFlags().IntVarP(&verifyCodeLength, "length", "l", 10, "要生成的验证码长度,默认生成长度为10个字符的验证码")
|
||
rootCmd.AddCommand(verifyCodeCmd)
|
||
}
|