diff --git a/lxc/completion.go b/lxc/completion.go index f47f83edb5cb..ea34fdef1247 100644 --- a/lxc/completion.go +++ b/lxc/completion.go @@ -1347,10 +1347,13 @@ 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, 0, len(g.conf.Remotes)) for remoteName := range g.conf.Remotes { + if !includeDefaultRemote && remoteName == g.conf.DefaultRemote { + continue + } + results = append(results, remoteName) } 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