summaryrefslogtreecommitdiffstats
path: root/prompt
diff options
context:
space:
mode:
Diffstat (limited to 'prompt')
-rw-r--r--prompt/prompt.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/prompt/prompt.go b/prompt/prompt.go
new file mode 100644
index 0000000..63c2a60
--- /dev/null
+++ b/prompt/prompt.go
@@ -0,0 +1,29 @@
+package prompt
+
+import (
+ "bufio"
+ "fmt"
+ "log"
+ "os"
+ "strings"
+)
+
+var Commands = make(map[string]func(args []string))
+
+func Read() {
+ sc := bufio.NewScanner(os.Stdin)
+ for sc.Scan() {
+ args := strings.Split(sc.Text(), " ")
+
+ cmd, ok := Commands[args[0]]
+ if !ok {
+ fmt.Println("unknown command")
+ continue
+ }
+
+ cmd(args[1:])
+ }
+ if err := sc.Err(); err != nil {
+ log.Println(err)
+ }
+}