forked from cfergeau/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
77 lines (67 loc) · 1.72 KB
/
helpers.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
package bus
import (
"github.com/wagoodman/go-partybus"
"github.com/wagoodman/go-progress"
"github.com/anchore/bubbly"
"github.com/dustin-decker/quill/internal/redact"
"github.com/dustin-decker/quill/quill/event"
)
func PublishTask(titles event.Title, context string, total int) *event.ManualStagedProgress {
prog := event.ManualStagedProgress{
Manual: progress.Manual{
Total: int64(total),
},
}
publish(partybus.Event{
Type: event.TaskType,
Source: event.Task{
Title: titles,
Context: context,
},
Value: progress.StagedProgressable(&struct {
progress.Stager
progress.Progressable
}{
Stager: &prog.Stage,
Progressable: &prog.Manual,
}),
})
return &prog
}
func Exit() {
publish(partybus.Event{
Type: event.CLIExitType,
})
}
func Report(report string) {
if publisher == nil {
// prevent any further actions taken on the report (such as redaction) since it won't be published anyway
return
}
publish(partybus.Event{
Type: event.CLIReportType,
Value: redact.Apply(report),
})
}
func Notify(message string) {
if publisher == nil {
// prevent any further actions taken on the report (such as redaction) since it won't be published anyway
return
}
publish(partybus.Event{
Type: event.CLINotificationType,
Value: redact.Apply(message),
})
}
func PromptForInput(message string, sensitive bool, validators ...func(string) error) *bubbly.Prompter {
if publisher == nil {
// prevent any further actions taken on the report (such as redaction) since it won't be published anyway
return nil
}
p := bubbly.NewPrompter(redact.Apply(message), sensitive, validators...)
publish(partybus.Event{
Type: event.CLIInputPromptType,
Value: bubbly.PromptWriter(p),
})
return p
}