From 3ba52b0c2c44a51af4814e2fdad017e3f6fc2193 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C3=A1lint=20R=C3=A9thelyi?= <rethelyibalint@gmail.com>
Date: Mon, 8 Mar 2021 13:11:04 +0100
Subject: [PATCH] check spell

---
 plab/check.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 plab/main.go  |  2 +-
 2 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 plab/check.go

diff --git a/plab/check.go b/plab/check.go
new file mode 100644
index 0000000..f4f1478
--- /dev/null
+++ b/plab/check.go
@@ -0,0 +1,58 @@
+package main
+
+import (
+	"fmt"
+	"git.sch.bme.hu/insert-epic-projlab-team-name-here/tooling/plab/helpers"
+	"io/ioutil"
+	"os/exec"
+	"strings"
+)
+
+var Check = helpers.Subcommand{
+	Name: "check",
+	Command: func(args []string) {
+		if len(args) != 1 {
+			fmt.Println("usage: check <approved words list in a file>")
+			return
+		}
+
+		huns := hunspell()
+		approved := approveds(args[0])
+
+		check(huns, approved)
+	},
+	Help: "check the spell",
+}
+
+func hunspell() []string {
+	b, e := exec.Command("bash", "-c", "hunspell -L -d hu_HU,en_GB,en_US -l -t $(find . -type f -name \"*.tex\" | tr \"\\n\" \" \")").Output()
+	if e != nil {
+		panic(e)
+	}
+	str := string(b)
+	return strings.Split(str, "\n")
+}
+
+func approveds(filename string) []string {
+	b, e := ioutil.ReadFile(filename)
+	if e != nil {
+		panic(e)
+	}
+	str := string(b)
+	return strings.Split(str, "\n")
+}
+
+func check(huns, approved []string) {
+	for _, h := range huns {
+		ignored := false
+		for _, a := range approved {
+			if strings.Contains(h, a) {
+				ignored = true
+				break
+			}
+		}
+		if !ignored {
+			fmt.Println(h)
+		}
+	}
+}
diff --git a/plab/main.go b/plab/main.go
index 64c583e..db1be0c 100644
--- a/plab/main.go
+++ b/plab/main.go
@@ -6,7 +6,7 @@ import (
 )
 
 func main() {
-	mainCmds := helpers.CmdFrom(os.Args[0], "go projlab tool", Timetable, Javadoc, Classdiag)
+	mainCmds := helpers.CmdFrom(os.Args[0], "go projlab tool", Timetable, Javadoc, Classdiag, Check)
 	if len(os.Args) < 2 {
 		os.Args = append(os.Args, "help")
 	}
-- 
GitLab