summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-04-08 01:44:15 +0530
committerAndinus <andinus@nand.sh>2020-04-08 01:44:15 +0530
commit34adb3a7e676a43cd692b4da14398a7d1b0be822 (patch)
tree52d071f21eda3fdeb9768ecefb41df1c7ee551e8 /cmd
parent47d22337b3a178b14e1cac287799f2c9dfb336e6 (diff)
downloadgrus-34adb3a7e676a43cd692b4da14398a7d1b0be822.tar.gz
Prepare for next rewrite
Diffstat (limited to 'cmd')
-rw-r--r--cmd/grus/env.go17
-rw-r--r--cmd/grus/grus.go60
-rw-r--r--cmd/grus/main_openbsd.go40
-rw-r--r--cmd/grus/main_other.go7
-rw-r--r--cmd/grus/usage.go10
5 files changed, 0 insertions, 134 deletions
diff --git a/cmd/grus/env.go b/cmd/grus/env.go
deleted file mode 100644
index 4d72030..0000000
--- a/cmd/grus/env.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package main
-
-import "os"
-
-// getEnv will check if the the key exists, if it does then it'll
-// return the value otherwise it will return fallback string.
-func getEnv(key, fallback string) string {
-	// We use os.LookupEnv instead of using os.GetEnv and checking
-	// if the length equals 0 because environment variable can be
-	// set and be of length 0. User could've set key="" which
-	// means the variable was set but the length is 0.
-	value, exists := os.LookupEnv(key)
-	if !exists {
-		value = fallback
-	}
-	return value
-}
diff --git a/cmd/grus/grus.go b/cmd/grus/grus.go
deleted file mode 100644
index 2e04de8..0000000
--- a/cmd/grus/grus.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package main
-
-import (
-	"database/sql"
-	"fmt"
-	"log"
-	"os"
-
-	"tildegit.org/andinus/grus/lexical"
-	"tildegit.org/andinus/grus/search"
-	"tildegit.org/andinus/grus/storage"
-)
-
-func grus() {
-	version := "v0.1.0"
-
-	// Early Check: If command was not passed then print usage and
-	// exit. Later command & service both are checked, this check
-	// is for version command. If not checked then running grus
-	// without any args will fail because os.Args[1] will panic
-	// the program & produce runtime error.
-	if len(os.Args) == 1 || len(os.Args[1]) == 0 {
-		printUsage()
-		os.Exit(0)
-	}
-
-	// Running just `grus` would've paniced the program here if
-	// length of os.Args was not checked beforehand because there
-	// would be no os.Args[1].
-	switch os.Args[1] {
-	case "version", "v", "-version", "--version", "-v":
-		fmt.Printf("Grus %s\n", version)
-		os.Exit(0)
-	case "help", "-help", "--help", "-h":
-		printUsage()
-		os.Exit(0)
-	case "init", "i":
-		db := storage.Init()
-		db.Conn.Close()
-		os.Exit(0)
-	}
-
-	// Initialize the database connection.
-	db := storage.InitConn()
-	defer db.Conn.Close()
-
-	word := os.Args[1]
-	sorted := lexical.Sort(word)
-
-	anagrams, err := search.Anagrams(sorted, db)
-	if err == sql.ErrNoRows {
-		fmt.Println("Word not found in database.")
-		return
-	} else if err != nil {
-		log.Fatalf("grus: Search failed :: %s", err)
-	}
-	for _, w := range anagrams {
-		fmt.Println(w)
-	}
-}
diff --git a/cmd/grus/main_openbsd.go b/cmd/grus/main_openbsd.go
deleted file mode 100644
index 5222bbe..0000000
--- a/cmd/grus/main_openbsd.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// +build openbsd
-
-package main
-
-import (
-	"log"
-	"os"
-
-	"golang.org/x/sys/unix"
-	"tildegit.org/andinus/grus/storage"
-	"tildegit.org/andinus/lynx"
-)
-
-func main() {
-	unveil()
-	grus()
-}
-
-func unveil() {
-	path := storage.GetDir()
-	err := os.MkdirAll(path, os.ModePerm)
-	if err != nil {
-		log.Fatalf("Unable to create directory: %s", path)
-	}
-
-	paths := make(map[string]string)
-
-	paths[path] = "rwc"
-
-	err = lynx.UnveilPathsStrict(paths)
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	// Block further unveil calls.
-	err = unix.UnveilBlock()
-	if err != nil {
-		log.Fatal(err)
-	}
-}
diff --git a/cmd/grus/main_other.go b/cmd/grus/main_other.go
deleted file mode 100644
index 88824ad..0000000
--- a/cmd/grus/main_other.go
+++ /dev/null
@@ -1,7 +0,0 @@
-// +build !openbsd
-
-package main
-
-func main() {
-	grus()
-}
diff --git a/cmd/grus/usage.go b/cmd/grus/usage.go
deleted file mode 100644
index 1749ba7..0000000
--- a/cmd/grus/usage.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package main
-
-import "fmt"
-
-func printUsage() {
-	fmt.Println("Usage: grus <word> / <command>")
-	fmt.Println("\nCommands: ")
-	fmt.Println(" help     Print help")
-	fmt.Println(" version  Print Grus version")
-}