mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
* 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
25 lines
596 B
Go
25 lines
596 B
Go
package config
|
|
|
|
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
|
|
}
|