Skip to content

Commit

Permalink
lxc: Update cmpStoragePoolVolumes usage
Browse files Browse the repository at this point in the history
On attach and detach commands, only include custom volumes as completion options.

Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Dec 6, 2024
1 parent 42db17a commit 7da0b4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
8 changes: 3 additions & 5 deletions lxc/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,17 +1361,15 @@ func (g *cmdGlobal) cmpStoragePoolWithVolume(toComplete string) ([]string, cobra
}

pool := strings.Split(toComplete, "/")[0]
volumes, compdir := g.cmpStoragePoolVolumes(pool)
volumes, compdir := g.cmpStoragePoolVolumes(pool, true)
if compdir == cobra.ShellCompDirectiveError {
return nil, compdir
}

var results []string
for _, volume := range volumes {
volName, volType := parseVolume("custom", volume)
if volType == "custom" {
results = append(results, pool+"/"+volName)
}
volName, _ := parseVolume("custom", volume)
results = append(results, pool+"/"+volName)
}

return results, cobra.ShellCompDirectiveNoFileComp
Expand Down
30 changes: 15 additions & 15 deletions lxc/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *cmdStorageVolumeAttach) command() *cobra.Command {
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -292,7 +292,7 @@ func (c *cmdStorageVolumeAttachProfile) command() *cobra.Command {
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -730,7 +730,7 @@ func (c *cmdStorageVolumeDelete) command() *cobra.Command {
}

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

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -816,7 +816,7 @@ func (c *cmdStorageVolumeDetach) command() *cobra.Command {
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -919,7 +919,7 @@ func (c *cmdStorageVolumeDetachProfile) command() *cobra.Command {
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -1028,7 +1028,7 @@ lxc storage volume edit [<remote>:]<pool> [<type>/]<volume> < volume.yaml
}

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

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -1255,7 +1255,7 @@ lxc storage volume get default virtual-machine/data snapshots.expiry
}

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

if len(args) == 2 {
Expand Down 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], false)
}

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -1969,7 +1969,7 @@ func (c *cmdStorageVolumeRename) command() *cobra.Command {
}

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

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -2109,7 +2109,7 @@ lxc storage volume set default virtual-machine/data snapshots.expiry=7d
}

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

// TODO all volume config keys
Expand Down 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], false)
}

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -2385,7 +2385,7 @@ lxc storage volume unset default virtual-machine/data snapshots.expiry
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -2445,7 +2445,7 @@ lxc storage volume snapshot create default v1 snap0 < config.yaml
}

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

return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -2573,7 +2573,7 @@ func (c *cmdStorageVolumeRestore) command() *cobra.Command {
}

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

if len(args) == 2 {
Expand Down Expand Up @@ -2660,7 +2660,7 @@ func (c *cmdStorageVolumeExport) command() *cobra.Command {
}

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

return nil, cobra.ShellCompDirectiveDefault
Expand Down

0 comments on commit 7da0b4f

Please sign in to comment.