Refactor awgo's unmaintainable global hell out of main
This commit is contained in:
parent
90d47f1a16
commit
5c6b71b3a8
24
main.go
24
main.go
@ -9,17 +9,21 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var wf *aw.Workflow
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
wf = aw.New()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
wf.Run(run)
|
translations := translateProgramArgs()
|
||||||
|
|
||||||
|
wf := aw.New()
|
||||||
|
wf.Run(func() {
|
||||||
|
for _, translation := range translations {
|
||||||
|
wf.NewItem(translation).Arg(translation).Valid(true)
|
||||||
|
}
|
||||||
|
wf.WarnEmpty("No results", "Try a different query?")
|
||||||
|
wf.SendFeedback()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() {
|
func translateProgramArgs() []string {
|
||||||
word, fromLang, toLang := parseProgramArgs(os.Args)
|
word, fromLang, toLang := parseProgramArgs(os.Args)
|
||||||
if fromLang == "" && toLang == "" {
|
if fromLang == "" && toLang == "" {
|
||||||
fromLang, toLang = decideWhatLanguagesToUse(word)
|
fromLang, toLang = decideWhatLanguagesToUse(word)
|
||||||
@ -28,11 +32,7 @@ func run() {
|
|||||||
t := trans.New(word)
|
t := trans.New(word)
|
||||||
t.Language = fromLang
|
t.Language = fromLang
|
||||||
translations := t.Translate(toLang)
|
translations := t.Translate(toLang)
|
||||||
for _, translation := range translations {
|
return translations
|
||||||
wf.NewItem(translation).Arg(translation).Valid(true)
|
|
||||||
}
|
|
||||||
wf.WarnEmpty("No results", "Try a different query?")
|
|
||||||
wf.SendFeedback()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseProgramArgs(args []string) (string, string, string) {
|
func parseProgramArgs(args []string) (string, string, string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user