feat: control systemd Docker daemon target

This commit is contained in:
proxyctl coordinator
2026-07-17 03:24:52 +08:00
parent 3003450dce
commit be3bbbbe04
11 changed files with 919 additions and 25 deletions
+42 -11
View File
@@ -26,14 +26,15 @@ type formState struct {
}
type Model struct {
application app.Module
snapshot app.Snapshot
page page
selected int
form formState
confirm bool
status string
applying bool
application app.Module
snapshot app.Snapshot
page page
selected int
form formState
confirm bool
targetConfirm *app.Intent
status string
applying bool
}
type targetOperationDone struct {
@@ -50,9 +51,18 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
if completed, ok := message.(targetOperationDone); ok {
m.applying = false
m.snapshot = completed.result.Snapshot
if completed.result.Err != nil {
if completed.result.Confirmation != "" {
intent := app.Intent{Kind: app.SetTargetDesired}
if m.targetConfirm != nil {
intent = *m.targetConfirm
}
m.targetConfirm = &intent
m.status = completed.result.Confirmation
} else if completed.result.Err != nil {
m.targetConfirm = nil
m.status = "\x1b[31mError: " + completed.result.Err.Error() + "\x1b[0m"
} else {
m.targetConfirm = nil
m.status = completed.result.Notice
}
return m, nil
@@ -74,6 +84,21 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
}
func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.targetConfirm != nil && !m.applying {
switch key.String() {
case "y":
intent := *m.targetConfirm
intent.Confirm = true
m.targetConfirm = nil
m.applying = true
m.status = ""
return m, func() tea.Msg { return targetOperationDone{result: m.application.Dispatch(intent)} }
case "n", "esc", "q":
m.targetConfirm = nil
m.status = ""
}
return m, nil
}
targets := m.availableTargets()
switch key.String() {
case "p":
@@ -93,8 +118,10 @@ func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
desired := selected.State != target.Enabled
m.applying = true
m.status = ""
intent := app.Intent{Kind: app.SetTargetDesired, TargetID: selected.ID, Enabled: desired}
m.targetConfirm = &intent
return m, func() tea.Msg {
return targetOperationDone{result: m.application.Dispatch(app.Intent{Kind: app.SetTargetDesired, TargetID: selected.ID, Enabled: desired})}
return targetOperationDone{result: m.application.Dispatch(intent)}
}
}
case "q", "esc", "ctrl+c":
@@ -288,7 +315,11 @@ func (m Model) mainView() string {
fmt.Fprintf(&b, "\nUnavailable %s: %s\n", item.Description.Name, item.AvailabilityEvidence)
}
}
b.WriteString("\nSpace: toggle ↑/k ↓/j: select p: manage Proxy Profiles q/Esc: quit\n")
if m.targetConfirm != nil && !m.applying {
b.WriteString("\ny: confirm n/Esc: cancel\n")
} else {
b.WriteString("\nSpace: toggle ↑/k ↓/j: select p: manage Proxy Profiles q/Esc: quit\n")
}
if m.status != "" {
fmt.Fprintf(&b, "\n%s\n", m.status)
}