Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 28, 2023
1 parent b696749 commit ee41258
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions pkg/actions/tools/k3d/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package k3d

import (
"encoding/json"
"fmt"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

type node struct {
Name string
Role string
RuntimeLabels struct {
K3dCluster string `json:"k3d.cluster"`
}
State struct {
Running bool
}
}

func (n node) style() string {
if n.State.Running {
return style.Carapace.KeywordPositive
}
return style.Carapace.KeywordNegative
}

func ActionNodes() carapace.Action {
return carapace.ActionExecCommand("k3d", "node", "list", "--output", "json")(func(output []byte) carapace.Action {
var nodes []node
if err := json.Unmarshal(output, &nodes); err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0)
for _, n := range nodes {
vals = append(vals, n.Name, fmt.Sprintf("%v.%v", n.RuntimeLabels.K3dCluster, n.Role), n.style())
}
return carapace.ActionStyledValuesDescribed(vals...)
})
}

0 comments on commit ee41258

Please sign in to comment.