diff --git a/completers/k3d_completer/cmd/cluster_create.go b/completers/k3d_completer/cmd/cluster_create.go index 738a2017a8..4f535177f2 100644 --- a/completers/k3d_completer/cmd/cluster_create.go +++ b/completers/k3d_completer/cmd/cluster_create.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/k3d" "github.com/spf13/cobra" ) @@ -48,10 +49,17 @@ func init() { clusterCmd.AddCommand(cluster_createCmd) carapace.Gen(cluster_createCmd).FlagCompletion(carapace.ActionMap{ - "api-port": carapace.ActionValues(), // TODO - "config": carapace.ActionFiles(), - "env": carapace.ActionValues(), - "gpus": carapace.ActionValues(), + "api-port": carapace.ActionValues(), // TODO + "config": carapace.ActionFiles(), + "env": carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues() // KEY=VALUE + default: + return k3d.ActionNodeFilter().List(";") + } + }), + "gpus": carapace.ActionValues(), // TODO "host-alias": carapace.ActionValues(), "image": carapace.ActionValues(), "k3s-arg": carapace.ActionValues(), diff --git a/pkg/actions/tools/k3d/node.go b/pkg/actions/tools/k3d/node.go index aef214a9da..7da155a305 100644 --- a/pkg/actions/tools/k3d/node.go +++ b/pkg/actions/tools/k3d/node.go @@ -67,3 +67,20 @@ func ActionNodes(opts NodeOpts) carapace.Action { return carapace.ActionStyledValuesDescribed(vals...) }) } + +func ActionNodeGroups() carapace.Action { + return carapace.ActionValues("server", "servers", "agent", "agents", "loadbalancer", "all") +} + +func ActionNodeFilter() carapace.Action { // TODO limit to specific cluster + return carapace.ActionMultiPartsN(":", 3, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return ActionNodeGroups() + case 1: + return carapace.ActionValues() // TODO subset + default: + return carapace.ActionValues() // TODO suffix + } + }) +}