summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-04-17 18:41:09 +0530
committerAndinus <andinus@nand.sh>2020-04-17 18:41:09 +0530
commit593a8ef24e917f99e02909fdb0d84d3e4916db91 (patch)
tree1d28f719fa19b591d9d2d27927e5537c1d7f6acb
parentd5b95cbec72d377dfce806b5aba4c9b0993ad185 (diff)
downloadgrus-0.3.1.tar.gz
Update to lynx v0.4.0 v0.3.1
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--main.go (renamed from grus.go)46
-rw-r--r--main_openbsd.go51
-rw-r--r--main_other.go7
5 files changed, 47 insertions, 61 deletions
diff --git a/go.mod b/go.mod
index 6b71a92..929e25c 100644
--- a/go.mod
+++ b/go.mod
@@ -4,5 +4,5 @@ go 1.13
 
 require (
 	golang.org/x/sys v0.0.0-20200406113430-c6e801f48ba2
-	tildegit.org/andinus/lynx v0.2.0
+	tildegit.org/andinus/lynx v0.4.0
 )
diff --git a/go.sum b/go.sum
index 8d3b70d..6160e3b 100644
--- a/go.sum
+++ b/go.sum
@@ -5,3 +5,5 @@ tildegit.org/andinus/lynx v0.1.0 h1:7YjyF8h7MBGKRgQZT0j0I3uHRPf3mI2GMiDujXVlLS0=
 tildegit.org/andinus/lynx v0.1.0/go.mod h1:/PCNkKwfJ7pb6ziHa76a4gYp1R9S1Ro4ANjQwzSpBIk=
 tildegit.org/andinus/lynx v0.2.0 h1:cBoAWqC/osZJE4VPdB0HhIEpMIC4A4eI9nEbHR/9Qvk=
 tildegit.org/andinus/lynx v0.2.0/go.mod h1:/PCNkKwfJ7pb6ziHa76a4gYp1R9S1Ro4ANjQwzSpBIk=
+tildegit.org/andinus/lynx v0.4.0 h1:bAxZLOdWy66+qJ3bDWjkbmJfCWTIOZ8hMGzYt7T7Bxk=
+tildegit.org/andinus/lynx v0.4.0/go.mod h1:/PCNkKwfJ7pb6ziHa76a4gYp1R9S1Ro4ANjQwzSpBIk=
diff --git a/grus.go b/main.go
index 15f3e0e..13971e7 100644
--- a/grus.go
+++ b/main.go
@@ -6,15 +6,18 @@ import (
 	"os"
 
 	"tildegit.org/andinus/grus/lexical"
+	"tildegit.org/andinus/lynx"
 )
 
-func grus() {
+func main() {
+	initGrus()
+
 	if len(os.Args) == 1 {
 		fmt.Println("Usage: grus <word> <dictionaries>")
 		os.Exit(1)
 	}
 
-	version := "v0.3.0"
+	version := "v0.3.1"
 
 	// Print version if first argument is version.
 	if os.Args[1] == "version" {
@@ -134,8 +137,47 @@ func grus() {
 		if !envVar["GRUS_SEARCH_ALL"] {
 			os.Exit(0)
 		}
+	}
+}
+
+func initGrus() {
+	// We need less permissions on these conditions.
+	if len(os.Args) == 1 ||
+		os.Args[1] == "version" ||
+		os.Args[1] == "env" {
+		err := lynx.PledgePromises("stdio")
+		panicOnErr(err)
+	} else {
+		err := lynx.PledgePromises("unveil stdio rpath")
+		panicOnErr(err)
+
+		unveil()
+
+		// Drop unveil from promises.
+		err = lynx.PledgePromises("stdio rpath")
+		panicOnErr(err)
+	}
+}
+
+func unveil() {
+	paths := make(map[string]string)
 
+	paths["/usr/share/dict"] = "r"
+	paths["/usr/local/share/dict"] = "r"
+
+	// Unveil user defined dictionaries.
+	if len(os.Args) >= 3 {
+		for _, dict := range os.Args[2:] {
+			paths[dict] = "r"
+		}
 	}
+	// This will not return error if the file doesn't exist.
+	err := lynx.UnveilPaths(paths)
+	panicOnErr(err)
+
+	// Block further unveil calls.
+	err = lynx.UnveilBlock()
+	panicOnErr(err)
 }
 
 func panicOnErr(err error) {
diff --git a/main_openbsd.go b/main_openbsd.go
deleted file mode 100644
index 7bbe995..0000000
--- a/main_openbsd.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// +build openbsd
-
-package main
-
-import (
-	"os"
-
-	"golang.org/x/sys/unix"
-	"tildegit.org/andinus/lynx"
-)
-
-func main() {
-	// We need less permissions on these conditions.
-	if len(os.Args) == 1 ||
-		os.Args[1] == "version" ||
-		os.Args[1] == "env" {
-		err := unix.PledgePromises("stdio")
-		panicOnErr(err)
-	} else {
-		err := unix.PledgePromises("unveil stdio rpath")
-		panicOnErr(err)
-
-		unveil()
-
-		// Drop unveil from promises.
-		err = unix.PledgePromises("stdio rpath")
-		panicOnErr(err)
-	}
-	grus()
-}
-
-func unveil() {
-	paths := make(map[string]string)
-
-	paths["/usr/share/dict"] = "r"
-	paths["/usr/local/share/dict"] = "r"
-
-	// Unveil user defined dictionaries.
-	if len(os.Args) >= 3 {
-		for _, dict := range os.Args[2:] {
-			paths[dict] = "r"
-		}
-	}
-	// This will not return error if the file doesn't exist.
-	err := lynx.UnveilPaths(paths)
-	panicOnErr(err)
-
-	// Block further unveil calls.
-	err = lynx.UnveilBlock()
-	panicOnErr(err)
-}
diff --git a/main_other.go b/main_other.go
deleted file mode 100644
index 88824ad..0000000
--- a/main_other.go
+++ /dev/null
@@ -1,7 +0,0 @@
-// +build !openbsd
-
-package main
-
-func main() {
-	grus()
-}