feat: Interactive 'uc ctx connection` command to select preferred cluster connection (#170)

* feat: Interactive uc command to select preferred cluster connection

https://github.com/psviderski/uncloud/issues/125

* Simplify connection selection and reordering by using the index instead of a pointer

* Move connection reordering logic to a new SetDefaultConnection on context
This commit is contained in:
Justin Bradford
2025-11-19 13:53:29 +10:00
committed by GitHub
parent 2e655d870c
commit 1d413734d8
3 changed files with 97 additions and 0 deletions
+18
View File
@@ -4,3 +4,21 @@ type Context struct {
Name string `yaml:"-"`
Connections []MachineConnection `yaml:"connections"`
}
func (c *Context) SetDefaultConnection(index int) {
// Do nothing if the index is out of range.
if index < 0 || index >= len(c.Connections) {
return
}
selected := c.Connections[index]
newConnections := make([]MachineConnection, 0, len(c.Connections))
newConnections = append(newConnections, selected)
for i, conn := range c.Connections {
if i != index {
newConnections = append(newConnections, conn)
}
}
c.Connections = newConnections
}