From a4c17dbae57972594b939ff0cff7ade0b98f2b3a Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Tue, 17 Dec 2024 17:01:34 -0700 Subject: [PATCH] lxc/completion: Fix snapshot shell completions for `lxc storage volume show` Fixes https://github.com/canonical/lxd/issues/14682. This commit fixes shell completions for snapshots when running `lxc storage volume show`. `GetStoragePoolVolumeNames` returns the full volume name including "/snapshots/", which is incorrect in the context of the CLI. Signed-off-by: Kadin Sayani --- lxc/completion.go | 10 +++++++++- lxc/storage_volume.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lxc/completion.go b/lxc/completion.go index f47f83edb5cb..d5233d70abe6 100644 --- a/lxc/completion.go +++ b/lxc/completion.go @@ -1631,9 +1631,17 @@ func (g *cmdGlobal) cmpStoragePoolVolumes(poolName string, volumeTypes ...string customVolumeNames := make([]string, 0, customKeyCount) - // Only include custom volumes + // Only complete volumes specified by volumeTypes. for _, volume := range volumes { _, volType := parseVolume("custom", volume) + + // Parse snapshots returned by GetStoragePoolVolumeNames. + if strings.Contains(volume, "/snapshots/") { + fields := strings.SplitN(volume, "/snapshots/", 2) + customVolumeNames = append(customVolumeNames, fields[0]+"/"+fields[1]) + continue + } + if shared.ValueInSlice(volType, volumeTypes) { customVolumeNames = append(customVolumeNames, volume) } diff --git a/lxc/storage_volume.go b/lxc/storage_volume.go index 8124f6624f99..a9f94bf08757 100644 --- a/lxc/storage_volume.go +++ b/lxc/storage_volume.go @@ -1383,7 +1383,7 @@ lxc storage volume info default virtual-machine/data } if len(args) == 1 { - return c.global.cmpStoragePoolVolumes(args[0]) + return c.global.cmpStoragePoolVolumes(args[0], "custom") } return nil, cobra.ShellCompDirectiveNoFileComp