From 0ac1a3d2b9499f88781d0fb67f7100198ff076dc Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 7 Jan 2025 16:32:45 -0700 Subject: [PATCH 1/4] lxc: Add dynamic `--project` completions to all commands Signed-off-by: Kadin Sayani --- lxc/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lxc/main.go b/lxc/main.go index 33b3db9c894c..9808c2de7d0f 100644 --- a/lxc/main.go +++ b/lxc/main.go @@ -99,6 +99,15 @@ For help with any of those, simply call them with --help.`)) app.PersistentFlags().BoolVarP(&globalCmd.flagQuiet, "quiet", "q", false, i18n.G("Don't show progress information")) app.PersistentFlags().BoolVar(&globalCmd.flagSubCmds, "sub-commands", false, i18n.G("Use with help or --help to view sub-commands")) + _ = app.RegisterFlagCompletionFunc("project", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + projects, directives := globalCmd.cmpProjects(toComplete) + if projects != nil { + return projects, directives + } + + return nil, cobra.ShellCompDirectiveError + }) + // Wrappers app.PersistentPreRunE = globalCmd.PreRun app.PersistentPostRunE = globalCmd.PostRun From 8c82d8ccb10f8384e501b9ffe1b0fc588e990e6c Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 7 Jan 2025 16:38:13 -0700 Subject: [PATCH 2/4] lxc: Add dynamic `--profile` completions to `lxc init|launch` Signed-off-by: Kadin Sayani --- lxc/init.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lxc/init.go b/lxc/init.go index 7a75df78a36a..7b5b92d8332c 100644 --- a/lxc/init.go +++ b/lxc/init.go @@ -75,6 +75,10 @@ lxc init ubuntu:24.04 v1 --vm -c limits.cpu=2 -c limits.memory=8GiB -d root,size return c.global.cmpImages(toComplete) } + _ = cmd.RegisterFlagCompletionFunc("profile", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return c.global.cmpProfiles(toComplete, true) + }) + return cmd } From 0e04efc2aca52200c74f69c3a06b3fd3da69f823 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 7 Jan 2025 16:40:24 -0700 Subject: [PATCH 3/4] lxc: Add `--mode` completions for `lxc move` Signed-off-by: Kadin Sayani --- lxc/move.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lxc/move.go b/lxc/move.go index a6795e2f9516..03da10fbbd97 100644 --- a/lxc/move.go +++ b/lxc/move.go @@ -80,6 +80,10 @@ lxc move / / return nil, cobra.ShellCompDirectiveNoFileComp } + _ = cmd.RegisterFlagCompletionFunc("mode", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"pull", "push", "relay"}, cobra.ShellCompDirectiveNoFileComp + }) + return cmd } From 4cf07829d89368cf53a47754e7eceec30d1d9427 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 7 Jan 2025 16:54:44 -0700 Subject: [PATCH 4/4] lxc: Remove extraneous space from `lxc move` completion Signed-off-by: Kadin Sayani --- lxc/move.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lxc/move.go b/lxc/move.go index 03da10fbbd97..5836ccd65072 100644 --- a/lxc/move.go +++ b/lxc/move.go @@ -70,7 +70,8 @@ lxc move / / cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return c.global.cmpInstances(toComplete) + instances, directives := c.global.cmpInstances(toComplete) + return instances, directives | cobra.ShellCompDirectiveNoSpace } if len(args) == 1 {