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 18, 2024
1 parent d537da4 commit a4c17db
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 @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion lxc/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4c17db

Please sign in to comment.