kjbc

A King James Bible concordance for the terminal.
git clone git://git.swab.dev/kjbc.git
Log | Files | Refs | README | LICENSE

commit 6f3b108b03ba31f449358117ec41c59651519b1d
parent 8368fd67b80cb949d1edb417100cfc1bd567843e
Author: Jaron Swab <jaron@swab.dev>
Date:   Sat,  5 Jun 2021 22:56:57 -0400

Auto output definition when only one entry is returned.

Diffstat:
Mmain.go | 72++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 44 insertions(+), 28 deletions(-)

diff --git a/main.go b/main.go @@ -20,6 +20,48 @@ func init() { flag.BoolVar(&usage, "u", false, "Display the usage information.") } +func getEntryNumber(term string) { + data, err := cons.Find(lang, term) + if err != nil { + fmt.Println(err) + } + + if len(*data) == 1 { + for _, v := range *data { + fmt.Printf("One entry found for \"%s\"...\n", term) + fmt.Printf("Entry Number: %s\n", v.Number) + getDefinition(v.Number) + } + } + + for i, v := range *data { + if i > 0 { + fmt.Printf("\nEntry Number: %s\n", v.Number) + } else { + fmt.Printf("Entry Number: %s\n", v.Number) + } + + if showVerses { + fmt.Printf("In Verses: ") + for j, w := range v.Verses { + if j == len(v.Verses)-1 { + fmt.Printf("%s\n", w) + } else { + fmt.Printf("%s, ", w) + } + } + } + } +} + +func getDefinition(term string) { + output, err := dicts.Get(lang, term) + if err != nil { + fmt.Println(err) + } + fmt.Println(output) +} + func main() { flag.Parse() if usage || len(os.Args) <= 2 { @@ -36,36 +78,10 @@ func main() { term := os.Args[len(os.Args)-1] if comm == "word" { - data, err := cons.Find(lang, term) - if err != nil { - fmt.Println(err) - } - - for i, v := range *data { - if i > 0 { - fmt.Printf("\nEntry Number: %s\n", v.Number) - } else { - fmt.Printf("Entry Number: %s\n", v.Number) - } - - if showVerses { - fmt.Printf("In Verses: ") - for j, w := range v.Verses { - if j == len(v.Verses)-1 { - fmt.Printf("%s\n", w) - } else { - fmt.Printf("%s, ", w) - } - } - } - } + getEntryNumber(term) } if comm == "entry" { - output, err := dicts.Get(lang, term) - if err != nil { - fmt.Println(err) - } - fmt.Println(output) + getDefinition(term) } }