-
Notifications
You must be signed in to change notification settings - Fork 8
/
prompt.go
54 lines (42 loc) · 1.09 KB
/
prompt.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
package config
import (
"bufio"
"fmt"
"os"
"strings"
)
type prompter struct {
reader *bufio.Reader
}
func NewPrompter() *prompter {
return &prompter{
bufio.NewReader(os.Stdin),
}
}
func (p *prompter) getValidYNInput(s string) bool {
text := strings.ToLower(p.getInput(s))
if text != "n" && text != "y" {
return p.getValidYNInput(s)
}
return text == "y"
}
func (p *prompter) getInput(s string) string {
fmt.Printf(s)
text, _ := p.reader.ReadString('\n')
return strings.Trim(text, " \n")
}
func (p *prompter) RemoveContext(id string) bool {
return p.getValidYNInput(fmt.Sprintf("Remove '%s' from context (Y/n)? ", id))
}
func (p *prompter) RemoveUser(id string) bool {
return p.getValidYNInput(fmt.Sprintf("Remove unused user '%s' from config (Y/n)? ", id))
}
func (p *prompter) WriteConfig() bool {
return p.getValidYNInput(fmt.Sprintf("Overwrite kubeconfig (Y/n)? "))
}
func (p *prompter) WriteConfigToPath() bool {
return p.getValidYNInput(fmt.Sprintf("Write kubeconfig to a different path (Y/n)? "))
}
func (p *prompter) GetPath() string {
return p.getInput(fmt.Sprintf("Path? "))
}