summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-22 13:43:54 +0530
committerAndinus <andinus@nand.sh>2020-03-22 13:43:54 +0530
commit9fde6e5a892b228c2d64af05b02380847573c832 (patch)
tree0d8fb21a7825b0e9f678180f5b66d866c8b38afa /cmd
parentc3ff3d068fdeacacec1f693bf9513742983814ad (diff)
downloadindus-9fde6e5a892b228c2d64af05b02380847573c832.tar.gz
Add initial version
Diffstat (limited to 'cmd')
-rw-r--r--cmd/indus/main.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/cmd/indus/main.go b/cmd/indus/main.go
index 38dd16d..ce3aa91 100644
--- a/cmd/indus/main.go
+++ b/cmd/indus/main.go
@@ -1,3 +1,48 @@
 package main
 
-func main() {}
+import (
+	"fmt"
+	"log"
+
+	"framagit.org/andinus/indus/clipboard"
+	"framagit.org/andinus/indus/fetch"
+	"framagit.org/andinus/indus/summarize"
+)
+
+func main() {
+	// Get the primary clipboard selection.
+	sel, err := clipboard.GetSel()
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	// If the selection is an empty string then the program should
+	// exit because otherwise Notify function will fail with
+	// non-zero exit code.
+	if len(sel) == 0 {
+		err = fmt.Errorf("clipboard: primary clipboard empty")
+		log.Fatal(err)
+	}
+
+	notifyWiki(sel)
+}
+
+func notifyWiki(sel string) {
+	// Fetch the summary from wikipedia.
+	w, err := fetch.Wikipedia(sel)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	// Get notification information.
+	n, err := summarize.Wikipedia(w)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	// Send a desktop notification to the user.
+	err = n.Notify()
+	if err != nil {
+		log.Fatal(err)
+	}
+}