github.com/TaceyWong/ctools@v0.1.1-0.20201221084458-4d7a8190b2ac/tools/shortme.go (about) 1 package tools 2 3 /* 4 short url tool 5 ori url -> short url & short url -> ori url 6 */ 7 8 import ( 9 "fmt" 10 11 "github.com/urfave/cli/v2" 12 "gopkg.in/AlecAivazis/survey.v1" 13 // surveyCore "gopkg.in/AlecAivazis/survey.v1/core" 14 ) 15 16 // https://github.com/tg123/go-htpasswd 17 // https://github.com/ByteFlinger/htpasswd/blob/master/htpasswd.go 18 19 // HtpasswdCMD HTPasswd cli command 20 var ShortMeCMD = cli.Command{ 21 Name: "shortme", 22 Aliases: []string{"hp"}, 23 Usage: "短网址", 24 Flags: []cli.Flag{ 25 &cli.StringFlag{ 26 Name: "lang, l", 27 Value: "english", 28 Usage: "Language for this", 29 }, 30 &cli.StringFlag{ 31 Name: "config, c", 32 Usage: "Load configuration from `FILE`", 33 }, 34 }, 35 Action: func(c *cli.Context) error { 36 ShortMe() 37 return nil 38 }, 39 } 40 41 // ShortMe encode & decode 42 func ShortMe() { 43 // surveyCore.QuestionIcon = "😵" 44 // surveyCore.HelpIcon = "x" 45 var qs = []*survey.Question{ 46 { 47 Name: "username", 48 Prompt: &survey.Input{ 49 Message: "What is the user name?", 50 Help: "The user name you want to to use fot auth/login"}, 51 Validate: survey.Required, 52 Transform: survey.Title, 53 }, 54 { 55 Name: "cryptotype", 56 Prompt: &survey.Select{ 57 Message: "Choose a crypto type:", 58 Options: []string{"Sha-1", "Md5", "Crypt"}, 59 Default: "Sha-1", 60 Help: "Md5:Apache only;Sha-1:Netscape and Apache ;Crypt:all Unix host", 61 }, 62 }, 63 { 64 Name: "password", 65 Prompt: &survey.Password{ 66 Message: "Please type your password", 67 Help: "The password you want to used for this user", 68 }, 69 70 Validate: survey.MinLength(6), 71 }, 72 } 73 result := struct { 74 Name string `survey:"username"` 75 CryptoType string 76 Password string 77 }{} 78 79 // perform the questions 80 err := survey.Ask(qs, &result) 81 if err != nil { 82 fmt.Println(err.Error()) 83 return 84 } 85 86 fmt.Printf("%s : %s : %s.\n", result.Name, result.CryptoType, result.Password) 87 88 }