Skip to content

Commit

Permalink
lxc/completion: Fix snapshot shell completions for `lxc storage volum…
Browse files Browse the repository at this point in the history
…e show`

Fixes canonical#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 <[email protected]>
  • Loading branch information
kadinsayani committed Dec 19, 2024
1 parent 2b27096 commit 1bcc8b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,9 +1634,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.
volumeName, snapshotName, found := strings.Cut(volume, "/snapshots")
if found {
customVolumeNames = append(customVolumeNames, volumeName+snapshotName)
continue
}

if shared.ValueInSlice(volType, volumeTypes) {
customVolumeNames = append(customVolumeNames, volume)
}
Expand Down
2 changes: 1 addition & 1 deletion lxc/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ lxc storage volume show default virtual-machine/data/snap0
}

if len(args) == 1 {
return c.global.cmpStoragePoolVolumes(args[0])
return c.global.cmpStoragePoolVolumes(args[0], "custom")
}

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down

0 comments on commit 1bcc8b3

Please sign in to comment.