From 7da0b4f5058ee384018aa08985cd1bda0afc09ad Mon Sep 17 00:00:00 2001 From: hamistao Date: Fri, 6 Dec 2024 02:50:21 -0300 Subject: [PATCH] lxc: Update `cmpStoragePoolVolumes` usage On attach and detach commands, only include custom volumes as completion options. Signed-off-by: hamistao --- lxc/completion.go | 8 +++----- lxc/storage_volume.go | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lxc/completion.go b/lxc/completion.go index f6910d99ce1b..d90744a96c17 100644 --- a/lxc/completion.go +++ b/lxc/completion.go @@ -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 diff --git a/lxc/storage_volume.go b/lxc/storage_volume.go index aa51f6a8cf93..c8feb8ea8031 100644 --- a/lxc/storage_volume.go +++ b/lxc/storage_volume.go @@ -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 { @@ -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 { @@ -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 @@ -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 { @@ -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 { @@ -1028,7 +1028,7 @@ lxc storage volume edit [:] [/] < volume.yaml } if len(args) == 1 { - return c.global.cmpStoragePoolVolumes(args[0]) + return c.global.cmpStoragePoolVolumes(args[0], false) } return nil, cobra.ShellCompDirectiveNoFileComp @@ -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 { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 @@ -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 { @@ -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