Skip to content

Commit

Permalink
lxc/completion: Add missing completions for lxc config unset
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Dec 5, 2024
1 parent 3e5d444 commit 058864c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
)
Expand Down Expand Up @@ -357,8 +358,10 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
return nil, cobra.ShellCompDirectiveError
}

// Fetch all config keys that can be set by a user.
allInstanceConfigKeys, _ := g.cmpInstanceAllKeys(instanceName)
instanceType := instance.Type

// Fetch all config keys that can be set by a user based on instance type.
allInstanceConfigKeys, _ := g.cmpInstanceKeys(instanceName)

// Convert slice to map[string]struct{} for O(1) lookups.
keySet := make(map[string]struct{}, len(allInstanceConfigKeys))
Expand All @@ -374,7 +377,14 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
// We only want to return the intersection between allInstanceConfigKeys and configKeys to avoid returning the full instance config.
_, exists := keySet[configKey]
if exists {
configKeys = append(configKeys, configKey)
if shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixes...) {
configKeys = append(configKeys, configKey)
continue
}

if instanceType == string(api.InstanceTypeContainer) && shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesContainer...) {
configKeys = append(configKeys, configKey)
}
}
}

Expand Down

0 comments on commit 058864c

Please sign in to comment.