-
Notifications
You must be signed in to change notification settings - Fork 3
/
provision.go
62 lines (47 loc) · 1.61 KB
/
provision.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
package models
import (
"fmt"
"strings"
"github.com/anchordotdev/cli/ui"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
)
type Provision struct {
Domains []string
certFile, chainFile, keyFile string
spinner spinner.Model
}
func (m *Provision) Init() tea.Cmd {
m.spinner = ui.WaitingSpinner()
return m.spinner.Tick
}
type ProvisionedFiles [3]string
func (m *Provision) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case ProvisionedFiles:
m.certFile = msg[0]
m.chainFile = msg[1]
m.keyFile = msg[2]
return m, tea.Quit
default:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
}
func (m *Provision) View() string {
var b strings.Builder
fmt.Fprintln(&b, ui.Header(fmt.Sprintf("Provision Certificate %s", ui.Whisper("`anchor lcl mkcert`"))))
if m.certFile == "" {
fmt.Fprintln(&b, ui.StepInProgress(fmt.Sprintf("Provisioning certificate for [%s]… %s",
ui.Domains(m.Domains), m.spinner.View())))
return b.String()
}
fmt.Fprintln(&b, ui.StepDone(fmt.Sprintf("Provisioned certificate for [%s].", ui.Domains(m.Domains))))
fmt.Fprintln(&b, ui.StepDone(fmt.Sprintf("Wrote certificate to %s", ui.Emphasize(m.certFile))))
fmt.Fprintln(&b, ui.StepDone(fmt.Sprintf("Wrote chain to %s", ui.Emphasize(m.chainFile))))
fmt.Fprintln(&b, ui.StepDone(fmt.Sprintf("Wrote key to %s", ui.Emphasize(m.keyFile))))
fmt.Fprintln(&b, ui.StepHint("You can use these certificate files to manually configure your application and"))
fmt.Fprintln(&b, ui.StepHint("start using HTTPS in your development environment."))
return b.String()
}