first commit, working version of define-cli

This commit is contained in:
Zack 2021-11-22 23:15:09 -05:00
commit 298a4aa69b
4 changed files with 72380 additions and 0 deletions

BIN
define-cli Executable file

Binary file not shown.

72325
dictionary.txt Normal file

File diff suppressed because it is too large Load Diff

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module ignition-ctrl/define-cli
go 1.17

52
main.go Normal file
View File

@ -0,0 +1,52 @@
package main
import (
"fmt"
"os"
"strings"
"bufio"
)
func main() {
var userword string
if len(os.Args) < 1 {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Please enter the word you wish to define:\n")
userword, _ = reader.ReadString('\n')
} else {
userword = os.Args[1]
}
file, err := os.Open("dictionary.txt")
if err != nil {
fmt.Println("Error! Dictionary file not opening!")
}
defer file.Close()
scanner := bufio.NewScanner(file)
itis := false
for scanner.Scan() {
//fmt.Println(scanner.Text())
definition := strings.Split(scanner.Text(), " ")
ifso, _ := CompareStrings(definition[0], userword)
if ifso {
fmt.Println(scanner.Text())
itis = true
}
}
if !(itis) {
fmt.Println("No definition found")
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
}
func CompareStrings(stringA, stringB string) (bool, error) {
if strings.EqualFold(stringA, stringB) {
return true, nil
} else {
return false, nil
}
}