mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user