From c238785e4cabef1a0dc602159ea9e1197976e953 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Mon, 16 Dec 2024 14:58:35 -0700 Subject: [PATCH] lxc/completion: Exclude default remote from `lxc remote switch|remove` completions Signed-off-by: Kadin Sayani --- lxc/completion.go | 9 +++++---- lxc/remote.go | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lxc/completion.go b/lxc/completion.go index f47f83edb5cb..6d1d75fcc8fd 100644 --- a/lxc/completion.go +++ b/lxc/completion.go @@ -1347,11 +1347,12 @@ func (g *cmdGlobal) cmpRemotes(includeAll bool) ([]string, cobra.ShellCompDirect // cmpRemoteNames provides shell completion for remote names. // It returns a list of remote names provided by `g.conf.Remotes` along with a shell completion directive. -func (g *cmdGlobal) cmpRemoteNames() ([]string, cobra.ShellCompDirective) { - var results []string - +func (g *cmdGlobal) cmpRemoteNames(includeDefaultRemote bool) ([]string, cobra.ShellCompDirective) { + results := make([]string, len(g.conf.Remotes)) for remoteName := range g.conf.Remotes { - results = append(results, remoteName) + if !includeDefaultRemote && remoteName != g.conf.DefaultRemote { + results = append(results, remoteName) + } } return results, cobra.ShellCompDirectiveNoFileComp diff --git a/lxc/remote.go b/lxc/remote.go index d236d824c605..aba54b53046f 100644 --- a/lxc/remote.go +++ b/lxc/remote.go @@ -877,7 +877,7 @@ func (c *cmdRemoteRename) command() *cobra.Command { cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return c.global.cmpRemoteNames() + return c.global.cmpRemoteNames(true) } return nil, cobra.ShellCompDirectiveNoFileComp @@ -958,7 +958,7 @@ func (c *cmdRemoteRemove) command() *cobra.Command { cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return c.global.cmpRemoteNames() + return c.global.cmpRemoteNames(false) } return nil, cobra.ShellCompDirectiveNoFileComp @@ -1022,7 +1022,7 @@ func (c *cmdRemoteSwitch) command() *cobra.Command { cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return c.global.cmpRemoteNames() + return c.global.cmpRemoteNames(false) } return nil, cobra.ShellCompDirectiveNoFileComp @@ -1070,7 +1070,7 @@ func (c *cmdRemoteSetURL) command() *cobra.Command { cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return c.global.cmpRemoteNames() + return c.global.cmpRemoteNames(true) } return nil, cobra.ShellCompDirectiveNoFileComp