Make better for CLI usage

This commit is contained in:
Brian Buller 2018-06-28 14:59:17 -05:00
parent bd82c95b31
commit 59c12cb89b
1 changed files with 31 additions and 66 deletions

97
main.go
View File

@ -8,80 +8,45 @@ import (
"github.com/kyokomi/emoji" "github.com/kyokomi/emoji"
) )
var emoticons map[string]string
func main() { func main() {
initEmoticons() if len(os.Args) < 2 || strings.HasSuffix(os.Args[1], "-help") {
// We default to "shrug" showUsage()
var done bool }
var getApprox bool
var which string var which string
if len(os.Args) == 2 { var matchWhich string
which = os.Args[1] for _, v := range os.Args {
if which == "help" { if v == "-a" {
showHelp() getApprox = true
} else if which == "help-emoji" {
allEmoji := emoji.CodeMap()
fmt.Println("== Supported Emoji ==")
for k, v := range allEmoji {
fmt.Println(k + " " + v)
}
os.Exit(0)
}
// it might be a one-word emoji request
allEmoji := emoji.CodeMap()
if _, done = allEmoji[which]; done {
tst1 := ":" + which + ":"
tst2 := emoji.Sprint(tst1)
if tst1 != tst2 {
fmt.Println(tst2)
done = true
}
} else { } else {
// Search for any emoji that contain this string which = v
var cnt int }
for k, v := range allEmoji { }
if strings.Contains(k, which) {
fmt.Println(k + " " + v) allEmoji := emoji.CodeMap()
cnt++ if !strings.HasPrefix(which, ":") && !strings.HasSuffix(which, ":") {
} matchWhich = ":" + which + ":"
} }
if cnt > 0 { if v, ok := allEmoji[matchWhich]; ok {
done = true fmt.Println(v)
} else { os.Exit(0)
fmt.Println("No emoji for " + which + " found.") } else if getApprox {
for k, v := range allEmoji {
if strings.Contains(k, which) {
fmt.Println(v)
os.Exit(0)
} }
} }
} }
if !done { os.Exit(1)
var i string
if i, done = emoticons[which]; done {
fmt.Println(i)
}
}
if !done {
showHelp()
}
} }
func showHelp() { func showUsage() {
fmt.Println("There are a *ton* of emoji supported, to list them, do \"help-emoji\"") allEmoji := emoji.CodeMap()
for k, v := range emoticons { fmt.Println("== Supported Emoji ==")
fmt.Println(k, v) for k, v := range allEmoji {
fmt.Println(k + " " + v)
} }
os.Exit(0) os.Exit(0)
} }
func initEmoticons() {
emoticons = make(map[string]string)
emoticons["ascii-bat"] = "°·_·°"
emoticons["ascii-bomb"] = "●~*"
emoticons["ascii-fish"] = ">°)))彡"
emoticons["ascii-flip"] = "(╯°□°)╯︵ ┻━┻"
emoticons["ascii-lenny"] = "( ͡° ͜ʖ ͡°)"
emoticons["ascii-octopus"] = "<コ:彡"
emoticons["ascii-shrug"] = "¯\\_(ツ)_/¯"
emoticons["ascii-smirk"] = "( ͡° ͜ʖ ͡°)"
emoticons["ascii-snake"] = "~>°)"
emoticons["ascii-star"] = "☆彡"
emoticons["ascii-tadpole"] = "(°°)"
}