emt/main.go

56 lines
949 B
Go
Raw Permalink Normal View History

2017-08-31 15:35:41 +00:00
package main
import (
"fmt"
"os"
2017-09-26 22:02:57 +00:00
"strings"
"github.com/kyokomi/emoji"
2017-08-31 15:35:41 +00:00
)
func main() {
2018-06-28 19:59:17 +00:00
if len(os.Args) < 2 || strings.HasSuffix(os.Args[1], "-help") {
showUsage()
}
var getApprox bool
var which string
2018-06-28 19:59:17 +00:00
var matchWhich string
2018-06-28 22:05:53 +00:00
allEmoji := emoji.CodeMap()
2018-06-28 19:59:17 +00:00
for _, v := range os.Args {
if v == "-a" {
getApprox = true
2018-06-28 22:05:53 +00:00
} else if v == "-completion-list" {
2021-05-28 19:44:16 +00:00
for k := range allEmoji {
2018-06-28 22:05:53 +00:00
fmt.Print(strings.Trim(k, ":"), " ")
}
} else {
2018-06-28 19:59:17 +00:00
which = v
}
}
2018-06-28 19:59:17 +00:00
if !strings.HasPrefix(which, ":") && !strings.HasSuffix(which, ":") {
matchWhich = ":" + which + ":"
2017-09-26 22:49:40 +00:00
}
2018-06-28 19:59:17 +00:00
if v, ok := allEmoji[matchWhich]; ok {
fmt.Println(v)
os.Exit(0)
} else if getApprox {
for k, v := range allEmoji {
if strings.Contains(k, which) {
fmt.Println(v)
}
}
}
2018-06-28 19:59:17 +00:00
os.Exit(1)
}
2018-06-28 19:59:17 +00:00
func showUsage() {
allEmoji := emoji.CodeMap()
fmt.Println("== Supported Emoji ==")
for k, v := range allEmoji {
fmt.Println(k + " " + v)
2017-08-31 15:35:41 +00:00
}
os.Exit(0)
2017-08-31 15:35:41 +00:00
}