-
Notifications
You must be signed in to change notification settings - Fork 120
/
menu_namespaces.go
80 lines (66 loc) · 1.5 KB
/
menu_namespaces.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package peirates
import (
"fmt"
"io"
"strings"
"github.com/ergochat/readline"
)
func setUpCompletionNsMenu() *readline.PrefixCompleter {
completer := readline.NewPrefixCompleter(
// [1] List namespaces [list]
readline.PcItem("list"),
// [2] Switch namespace [switch]
readline.PcItem("switch"),
)
return completer
}
func interactiveNSMenu(connectionString *ServerInfo) {
// Set up main menu tab completion
var completer *readline.PrefixCompleter = setUpCompletionNsMenu()
l, err := readline.NewEx(&readline.Config{
Prompt: "\033[31m»\033[0m ",
HistoryFile: "/tmp/peirates.history",
AutoComplete: completer,
InterruptPrompt: "^C",
EOFPrompt: "exit",
HistorySearchFold: true,
// FuncFilterInputRune: filterInput,
})
if err != nil {
panic(err)
}
defer l.Close()
// l.CaptureExitSignal()
println(`
[1] List namespaces [list]
[2] Switch namespace [switch]
`)
fmt.Printf("\nPeirates (ns-menu):># ")
var input string
line, err := l.Readline()
if err == readline.ErrInterrupt {
if len(line) == 0 {
println("Empty line")
pauseToHitEnter(true)
return
}
} else if err == io.EOF {
println("Empty line")
pauseToHitEnter(true)
return
}
input = strings.TrimSpace(line)
if err != nil {
return
}
switch input {
case "1", "list":
listNamespaces(*connectionString)
case "2", "switch":
menuSwitchNamespaces(connectionString)
default:
fmt.Printf("You must choose option from the options above.")
pauseToHitEnter(true)
return
}
}