Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Exclude default remote from lxc remote switch|remove shell completions #14677

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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
Loading