[pve-devel] [PATCH guest-common] Bash completion helper for snapshot name
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Nov 14 12:03:45 CET 2018
On 11/12/18 2:58 PM, Rhonda D'Vine wrote:
> This is the bash completion helper function for completing the snapshot
> name. This is used both in qemu-server and pve-container.
>
> This patch is the base for the patches in qemu-server and pve-container.
>
> Signed-off-by: Rhonda D'Vine <rhonda at proxmox.com>
> ---
> PVE/AbstractConfig.pm | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
> index 4cfe9bc..12086b1 100644
> --- a/PVE/AbstractConfig.pm
> +++ b/PVE/AbstractConfig.pm
> @@ -697,4 +697,17 @@ sub snapshot_rollback {
> $class->lock_config($vmid, $updatefn);
> }
>
> +# bash completion helper
> +
> +sub complete_snapshot_name {
> + my ($class) = @_;
First, please use a sane signature, e.g., something like:
my ($class, $cmd, $pname, $cur, $args) = @_;
or even pass only a subset of args to the handler, maybe even better just
the $vmid as the callee then can have the VMID on different fixed positions.
Could call this 'snapshot_list' as it's not a specific completion helper
only, it can just be easily used as one.
Further, this is pretty fragile, e.g., if I try it with a invalid, a not
existing or a VMID from the other class I get something like:
> Configuration file 'nodes/dev5/lxc/100.conf' does not exist
or:
> pct config asd --snapshot unknown file type 'nodes/dev5/lxc/asd.conf'
printed when hitting TAB TAB, but there should be just no completion for this
case.
> + my $vmid = $_[4][0];
> +
> + my $conf = $class->load_config($vmid);
> +
> + my $snapshot = [ keys %{$conf->{snapshots}} ];
> +
> + return $snapshot;
> +}
> +
> 1;
>
More information about the pve-devel
mailing list