-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
125 lines (108 loc) · 2.53 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"flag"
"fmt"
"os"
"sort"
"strings"
"github.com/fatih/color"
)
const usage = `Usage of gmj:
$ gmj -l
Lists all available emojis, its codepoint, shortcode, and usage.
$ gmj -c bug
Gets an emoji codepoint by a provided shortcode.
$ gmj -u bug
Shows a use case by a provided shortcode.
$ gmj -s dev
Goes through a list of emojis and returns more feasiable emojis to be
used by a provided keyword.
`
func main() {
flag.Usage = func() {
fmt.Fprint(flag.CommandLine.Output(), usage)
}
emojisList := flag.Bool("l", false, "")
emojiCode := flag.String("c", "", "")
emojiUsage := flag.String("u", "", "")
lookupKeyword := flag.String("s", "", "")
flag.Parse()
keys := make([]string, 0, len(Emojis))
for key := range Emojis {
keys = append(keys, key)
}
sort.Strings(keys)
if *emojisList {
fmt.Println(color.HiBlueString("Codepoint - Shortcode - Usage"))
for _, key := range keys {
fmt.Printf(
"%s - :%s: - %s\n",
Emojis[key]["codepoint"],
color.RedString(key),
color.CyanString(Emojis[key]["usage"]),
)
}
fmt.Println(
color.HiBlueString("Total number of emojis: "),
len(keys),
)
os.Exit(0)
}
if len(*lookupKeyword) > 0 {
sum := 0
fmt.Println(color.HiBlueString("Codepoint - Shortcode - Usage"))
lookupKeyword := strings.ToLower(*lookupKeyword)
for _, key := range keys {
usage := strings.ToLower(Emojis[key]["usage"])
key := strings.ToLower(key)
if strings.Contains(usage, lookupKeyword) ||
strings.Contains(key, lookupKeyword) {
fmt.Printf(
"%s - :%s: - %s\n",
Emojis[key]["codepoint"],
color.RedString(key),
color.CyanString(Emojis[key]["usage"]),
)
sum += 1
}
}
if sum == 0 {
fmt.Printf(
"None of emojis found by a shortcode %s\n",
color.HiYellowString(lookupKeyword),
)
}
fmt.Println(color.HiBlueString("Total number of emojis: "), sum)
os.Exit(0)
}
if len(*emojiCode) > 0 {
emojiCode := strings.ToLower(*emojiCode)
value, key := Emojis[emojiCode]
if key {
fmt.Println(value["codepoint"])
} else {
fmt.Printf(
"Cannot get an emoji by a shortcode: %s\n",
color.HiRedString(emojiCode),
)
os.Exit(1)
}
os.Exit(0)
}
if len(*emojiUsage) > 0 {
emojiUsage := strings.ToLower(*emojiUsage)
value, key := Emojis[emojiUsage]
if key {
fmt.Printf("%s\n", color.HiBlueString(value["usage"]))
os.Exit(0)
} else {
fmt.Printf(
"Cannot get an emoji usage by a shortcode: %s\n",
color.HiRedString(emojiUsage),
)
os.Exit(1)
}
}
flag.Usage()
os.Exit(1)
}