forked from sensu/sensu-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts.go
71 lines (60 loc) · 1.53 KB
/
prompts.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
package helpers
import (
"fmt"
"github.com/AlecAivazis/survey"
"github.com/sensu/sensu-go/cli/elements/globals"
)
// ConfirmDelete confirm a deletion operation before it is completed.
func ConfirmDelete(name string) bool {
confirm := &ConfirmDestructiveOp{
Type: "resource",
Op: "delete",
}
ok, _ := confirm.Ask(name)
return ok
}
// ConfirmDestructiveOp presents prompt for a destructive operation.
type ConfirmDestructiveOp struct {
Type string
Op string
}
// Ask presents prompt confirming a destructive operation.
func (c *ConfirmDestructiveOp) Ask(name string) (bool, error) {
question := globals.TitleStyle("Are you sure you would like to ") +
globals.CTATextStyle(c.Op) +
globals.TitleStyle(fmt.Sprintf(" %s '", c.Type)) +
globals.PrimaryTextStyle(name) +
globals.TitleStyle("'?")
confirm := &Confirm{
Message: question,
Default: false,
}
return confirm.Ask()
}
// Confirm an operation before it is completed
type Confirm struct {
Message string
Default bool
}
// Ask executes confirmation of operation
func (c *Confirm) Ask() (bool, error) {
prompt := &survey.Confirm{
Message: c.Message,
Default: c.Default,
}
confirmation := false
err := survey.AskOne(prompt, &confirmation, nil)
if err != nil {
return false, err
}
return confirmation, nil
}
// ConfirmOptOut confirm an opt-out operation before it is completed.
func ConfirmOptOut() bool {
c := &Confirm{
Message: "Are you sure you would like to opt-out of tessen? We'd hate to see you go!",
Default: false,
}
ok, _ := c.Ask()
return ok
}