This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_ui.go
112 lines (83 loc) · 2.37 KB
/
fake_ui.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package fakes
import (
"fmt"
. "github.com/cloudfoundry/bosh-cli/ui/table"
)
type FakeUI struct {
Said []string
Errors []string
Blocks []string
Table Table
Tables []Table
AskedTextLabels []string
AskedText []Answer
AskedPasswordLabels []string
AskedPasswords []Answer
AskedChoiceCalled bool
AskedChoiceLabel string
AskedChoiceOptions []string
AskedChoiceChosens []int
AskedChoiceErrs []error
AskedConfirmationCalled bool
AskedConfirmationErr error
Interactive bool
Flushed bool
}
type Answer struct {
Text string
Error error
}
func (ui *FakeUI) ErrorLinef(pattern string, args ...interface{}) {
ui.Errors = append(ui.Errors, fmt.Sprintf(pattern, args...))
}
func (ui *FakeUI) PrintLinef(pattern string, args ...interface{}) {
ui.Said = append(ui.Said, fmt.Sprintf(pattern, args...))
}
func (ui *FakeUI) BeginLinef(pattern string, args ...interface{}) {
ui.Said = append(ui.Said, fmt.Sprintf(pattern, args...))
}
func (ui *FakeUI) EndLinef(pattern string, args ...interface{}) {
ui.Said = append(ui.Said, fmt.Sprintf(pattern, args...))
}
func (ui *FakeUI) PrintBlock(block string) {
ui.Blocks = append(ui.Blocks, block)
}
func (ui *FakeUI) PrintErrorBlock(block string) {
ui.Blocks = append(ui.Blocks, block)
}
func (ui *FakeUI) PrintTable(table Table) {
ui.Table = table
ui.Tables = append(ui.Tables, table)
}
func (ui *FakeUI) AskForText(label string) (string, error) {
ui.AskedTextLabels = append(ui.AskedTextLabels, label)
answer := ui.AskedText[0]
ui.AskedText = ui.AskedText[1:]
return answer.Text, answer.Error
}
func (ui *FakeUI) AskForChoice(label string, options []string) (int, error) {
ui.AskedChoiceCalled = true
ui.AskedChoiceLabel = label
ui.AskedChoiceOptions = options
chosen := ui.AskedChoiceChosens[0]
ui.AskedChoiceChosens = ui.AskedChoiceChosens[1:]
err := ui.AskedChoiceErrs[0]
ui.AskedChoiceErrs = ui.AskedChoiceErrs[1:]
return chosen, err
}
func (ui *FakeUI) AskForPassword(label string) (string, error) {
ui.AskedPasswordLabels = append(ui.AskedPasswordLabels, label)
answer := ui.AskedPasswords[0]
ui.AskedPasswords = ui.AskedPasswords[1:]
return answer.Text, answer.Error
}
func (ui *FakeUI) AskForConfirmation() error {
ui.AskedConfirmationCalled = true
return ui.AskedConfirmationErr
}
func (ui *FakeUI) IsInteractive() bool {
return ui.Interactive
}
func (ui *FakeUI) Flush() {
ui.Flushed = true
}