Skip to content

Commit

Permalink
lxc/completion: Exclude default remote from `lxc remote switch|remove…
Browse files Browse the repository at this point in the history
…` completions

Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Dec 17, 2024
1 parent 7931651 commit c238785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lxc/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c238785

Please sign in to comment.