-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
92 lines (79 loc) · 2.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/alexflint/go-arg"
)
var args struct {
NameFile string `arg:"-n,--names" help:"file containing list of names to generate usernames for"`
Domain string `arg:"-d,--domain" help:"generate emails from name list containing specified domain"`
SaveFile string `arg:"-s,--save" help:"save userlist to specified file"`
}
var join = strings.Join
func writeUserList(userList []string) {
f, err := os.Create(args.SaveFile)
if err != nil {
fmt.Println(err.Error())
}
for _, user := range userList {
fmt.Fprintln(f, user)
}
fmt.Printf("usernames written to: %s\n", args.SaveFile)
}
func main() {
arg.MustParse(&args)
if args.NameFile == "" {
fmt.Println("must provide a file containing a list of names with `-n`")
return
}
f, err := os.Open(args.NameFile)
if err != nil {
fmt.Println(err.Error())
return
}
var names []string
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
names = append(names, line)
}
var userList []string
for _, name := range names {
lower := strings.ToLower(name)
userList = append(userList, strings.Replace(lower, " ", ".", -1))
userList = append(userList, strings.Replace(lower, " ", "-", -1))
userList = append(userList, strings.Replace(lower, " ", "", -1))
split := strings.Split(lower, " ")
var initial, firstName, lastName, lastInitial string
firstName = split[0]
initial = string(firstName[0])
lastName = split[len(split)-1]
lastInitial = string(lastName[0])
//firstName, initial, lastName, lastInitial = split[0], string(firstName[0]), split[len(split)-1], string(lastName[0])
userList = append(userList, join([]string{lastName, firstName}, ""))
userList = append(userList, join([]string{initial, lastName}, ""))
userList = append(userList, join([]string{lastName, initial}, ""))
userList = append(userList, join([]string{firstName, lastInitial}, ""))
userList = append(userList, join([]string{initial, ".", lastName}, ""))
userList = append(userList, join([]string{lastInitial, ".", firstName}, ""))
userList = append(userList, join([]string{firstName, ".", lastInitial}, ""))
userList = append(userList, join([]string{initial, "-", lastName}, ""))
userList = append(userList, join([]string{lastName, firstName[:4]}, "")) //Amazon email format
userList = append(userList, firstName)
userList = append(userList, lastName)
}
if args.Domain != "" {
for _, user := range userList {
userList = append(userList, fmt.Sprintf("%s@%s", user, args.Domain))
}
}
if args.SaveFile != "" {
writeUserList(userList)
} else {
for _, user := range userList {
fmt.Println(user)
}
}
}