ag_tools/cmd/verify_code.go

29 lines
652 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}