From 06348f45228c7ee6f954f064bd88889d65256515 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 26 Sep 2023 01:07:20 +0200 Subject: [PATCH] tmp --- .../k3d_completer/cmd/cluster_create.go | 44 +++++++++++++++++++ completers/k3d_completer/cmd/node_create.go | 10 +++++ completers/k3d_completer/cmd/node_list.go | 6 +++ completers/k3d_completer/cmd/registry_.go | 18 -------- 4 files changed, 60 insertions(+), 18 deletions(-) delete mode 100644 completers/k3d_completer/cmd/registry_.go diff --git a/completers/k3d_completer/cmd/cluster_create.go b/completers/k3d_completer/cmd/cluster_create.go index a7d6a260f0..738a2017a8 100644 --- a/completers/k3d_completer/cmd/cluster_create.go +++ b/completers/k3d_completer/cmd/cluster_create.go @@ -46,4 +46,48 @@ func init() { cluster_createCmd.Flags().StringSliceP("volume", "v", []string{}, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`") cluster_createCmd.Flags().Bool("wait", false, "Wait for the server(s) to be ready before returning. Use '--timeout DURATION' to not wait forever.") 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(), + "host-alias": carapace.ActionValues(), + "image": carapace.ActionValues(), + "k3s-arg": carapace.ActionValues(), + "k3s-node-label": carapace.ActionValues(), + "lb-config-override": carapace.ActionValues(), + "network": carapace.ActionValues(), + "port": carapace.ActionValues(), + "registry-config": carapace.ActionValues(), + "registry-create": carapace.ActionValues(), + "registry-use": carapace.ActionValues(), + "runtime-label": carapace.ActionValues(), + "runtime-ulimit": carapace.ActionValues(), + "servers": carapace.ActionValues(), + "servers-memory": carapace.ActionValues(), + "subnet": carapace.ActionValues(), + "timeout": carapace.ActionValues(), + "token": carapace.ActionValues(), + "volume": carapace.ActionValues(), + }) +} + +func x() { + // KEY[=VALUE][@NODEFILTER[;NODEFILTER...]] + carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionMultiPartsN("=", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues("TODO:key") + default: + return carapace.ActionValues("TODO:value") + } + }) + default: + return carapace.ActionValues("TODO:nodefilter").List(";") + } + }).List(",") } diff --git a/completers/k3d_completer/cmd/node_create.go b/completers/k3d_completer/cmd/node_create.go index 3bee456da3..8d82b7055b 100644 --- a/completers/k3d_completer/cmd/node_create.go +++ b/completers/k3d_completer/cmd/node_create.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" "github.com/spf13/cobra" ) @@ -28,4 +29,13 @@ func init() { node_createCmd.Flags().StringP("token", "t", "", "Override cluster token (required when connecting to an external cluster)") node_createCmd.Flags().Bool("wait", false, "Wait for the node(s) to be ready before returning.") nodeCmd.AddCommand(node_createCmd) + + // TODO + carapace.Gen(node_createCmd).FlagCompletion(carapace.ActionMap{ + // "cluster": carapace.ActionValues(), + // "image": carapace.ActionValues(), + "k3s-arg": bridge.ActionCarapaceBin("k3s").Split(), // TODO verify + // "network": carapace.ActionValues(), + "role": carapace.ActionValues("server", "agent"), + }) } diff --git a/completers/k3d_completer/cmd/node_list.go b/completers/k3d_completer/cmd/node_list.go index c127295ec9..ce6e43b599 100644 --- a/completers/k3d_completer/cmd/node_list.go +++ b/completers/k3d_completer/cmd/node_list.go @@ -18,4 +18,10 @@ func init() { node_listCmd.Flags().Bool("no-headers", false, "Disable headers") node_listCmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml") nodeCmd.AddCommand(node_listCmd) + + carapace.Gen(node_listCmd).FlagCompletion(carapace.ActionMap{ + "output": carapace.ActionValues("json", "yaml"), + }) + + // TODO positional } diff --git a/completers/k3d_completer/cmd/registry_.go b/completers/k3d_completer/cmd/registry_.go deleted file mode 100644 index 9c82506022..0000000000 --- a/completers/k3d_completer/cmd/registry_.go +++ /dev/null @@ -1,18 +0,0 @@ -package cmd - -import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" -) - -var registry_Cmd = &cobra.Command{ - Use: "", - Short: "", - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(registry_Cmd).Standalone() - - registryCmd.AddCommand(registry_Cmd) -}