Skip to content

Commit 9592285

Browse files
committed
lxc/completion: Add missing completions for lxc config unset
Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
1 parent 3e5d444 commit 9592285

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lxc/completion.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
"github.com/canonical/lxd/lxd/instance/instancetype"
910
"github.com/canonical/lxd/shared"
1011
"github.com/canonical/lxd/shared/api"
1112
)
@@ -357,8 +358,10 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
357358
return nil, cobra.ShellCompDirectiveError
358359
}
359360

360-
// Fetch all config keys that can be set by a user.
361-
allInstanceConfigKeys, _ := g.cmpInstanceAllKeys(instanceName)
361+
instanceType := instance.Type
362+
363+
// Fetch all config keys that can be set by a user based on instance type.
364+
allInstanceConfigKeys, _ := g.cmpInstanceKeys(instanceName)
362365

363366
// Convert slice to map[string]struct{} for O(1) lookups.
364367
keySet := make(map[string]struct{}, len(allInstanceConfigKeys))
@@ -374,7 +377,11 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She
374377
// We only want to return the intersection between allInstanceConfigKeys and configKeys to avoid returning the full instance config.
375378
_, exists := keySet[configKey]
376379
if exists {
377-
configKeys = append(configKeys, configKey)
380+
if shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixes...) {
381+
configKeys = append(configKeys, configKey)
382+
} else if instanceType == string(api.InstanceTypeContainer) && shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesContainer...) {
383+
configKeys = append(configKeys, configKey)
384+
}
378385
}
379386
}
380387

0 commit comments

Comments
 (0)