Skip to content

Commit

Permalink
lxc/completion: Fix cmpInstanceSetKeys to return set instance confi…
Browse files Browse the repository at this point in the history
…g keys

This commit fixes `cmpInstanceSetKeys` to return any set instance
configuration key rather than just keys with known prefixes. We don't
need to validate type here since a VM specific config key cannot be set
for a container, and vice-versa, and we only return config keys that
show up in an instance's full config.

Signed-off-by: Kadin Sayani <[email protected]>
(cherry picked from commit 4307f76)
  • Loading branch information
kadinsayani committed Dec 19, 2024
1 parent 89b9602 commit fed5f9d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
return nil, cobra.ShellCompDirectiveError
}

instanceType := instance.Type

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

Expand All @@ -377,12 +375,9 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
for configKey := range instance.Config {
// We only want to return the intersection between allInstanceConfigKeys and configKeys to avoid returning the full instance config.
_, exists := keySet[configKey]
if exists {
if shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesAny...) {
configKeys = append(configKeys, configKey)
} else if instanceType == string(api.InstanceTypeContainer) && shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesContainer...) {
configKeys = append(configKeys, configKey)
}
knownPrefixes := append(instancetype.ConfigKeyPrefixesAny, instancetype.ConfigKeyPrefixesContainer...)
if exists || strings.HasPrefix(configKey, instancetype.ConfigVolatilePrefix) || shared.StringHasPrefix(configKey, knownPrefixes...) {
configKeys = append(configKeys, configKey)
}
}

Expand Down

0 comments on commit fed5f9d

Please sign in to comment.