Smarter argument Parsing

This commit is contained in:
Brian Buller 2017-09-26 17:49:40 -05:00
parent fe59d61d76
commit 0937f3efeb

30
main.go
View File

@ -14,21 +14,41 @@ func main() {
initEmoticons() initEmoticons()
// We default to "shrug" // We default to "shrug"
emt := "¯\\_(ツ)_/¯" emt := "¯\\_(ツ)_/¯"
if len(os.Args) > 1 { var done bool
if len(os.Args) == 2 {
which := os.Args[1] which := os.Args[1]
if which == "help" { if which == "help" {
fmt.Println("There are a *ton* of emoji supported, to list them, do \"help-emoji\"")
for k, v := range emoticons { for k, v := range emoticons {
fmt.Println(k, v) fmt.Println(k, v)
} }
os.Exit(0) os.Exit(0)
} else if which == "emoji" { } else if which == "help-emoji" {
rest := strings.Join(os.Args[2:], " ") allEmoji := emoji.CodeMap()
emt = emoji.Sprint(rest) fmt.Println("== Supported Emoji ==")
for k, v := range allEmoji {
fmt.Println(k + " " + v)
}
os.Exit(0)
} else { } else {
if i, ok := emoticons[which]; ok { var i string
if i, done = emoticons[which]; done {
emt = i emt = i
} }
} }
if !done {
// it might be a one-word emoji request
tst1 := ":" + which + ":"
tst2 := emoji.Sprint(tst1)
if tst1 != tst2 {
emt = tst2
done = true
}
}
}
if !done {
rest := strings.Join(os.Args[1:], " ")
emt = emoji.Sprint(rest)
} }
fmt.Println(emt) fmt.Println(emt)
} }