-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.go
39 lines (30 loc) · 852 Bytes
/
form.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
package main
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/luthermonson/go-proxmox"
)
func createFormOptions(vms proxmox.VirtualMachines) []huh.Option[string] {
var options []huh.Option[string]
for _, v := range vms {
vmName := v.Name
vmStatus := v.Status
vmStatusSymbolMap := map[string]string{
"running": "🟢",
"stopped": "🔴",
}
var vmStatysSymbol string
if value, ok := vmStatusSymbolMap[vmStatus]; ok {
vmStatysSymbol = value
vmDisplayName := fmt.Sprintf("%s %s", vmStatysSymbol, vmName)
if vmStatus == "running" {
options = append(options, huh.NewOption(vmDisplayName, vmName).Selected(true))
} else if vmStatus == "stopped" {
options = append(options, huh.NewOption(vmDisplayName, vmName))
}
} else {
fmt.Println("Value not found in the map.")
}
}
return options
}