-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
53 lines (50 loc) · 1 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"strings"
)
// HandleCommand takes the latest user input, parses it, and calls the wanted function.
func (a *Apollo) handleCommand() {
args := strings.Split(string(a.input), " ")
command := args[0]
switch command {
case "/quit":
a.running = false
case "/help":
if len(args) == 1 {
a.printHelp()
} else {
a.printDetailedHelp(args[1])
}
case "/open":
if len(args) == 2 {
err := a.openTab(args[1])
if err != nil {
a.logError(err.Error())
}
} else {
a.logError("term: invalid number of arguments")
}
case "/close":
err := a.closeCurrentTab()
if err != nil {
a.logError(err.Error())
}
case "/set":
if len(args) == 3 {
err := a.c.set(args[1], args[2])
if err != nil {
a.logError(err.Error())
} else {
a.log("{b}│ {d}Configuration changed.")
}
} else {
a.logError("term: invalid number of arguments")
}
case "/config":
a.printConfig()
case "/stats":
a.printStats()
default:
a.logError("term: invalid command")
}
}