From f7621c012631044e19140491b1381eec98352af1 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 18 Sep 2015 09:33:09 +0200 Subject: [PATCH] improve bash completions --- PVE/API2/Storage/Content.pm | 9 +++++++-- PVE/Storage.pm | 21 +++++++++++++++++++++ PVE/Storage/Plugin.pm | 3 ++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm index 1b09f53..a7e9fe3 100644 --- a/PVE/API2/Storage/Content.pm +++ b/PVE/API2/Storage/Content.pm @@ -111,12 +111,17 @@ __PACKAGE__->register_method ({ additionalProperties => 0, properties => { node => get_standard_option('pve-node'), - storage => get_standard_option('pve-storage-id'), + storage => get_standard_option('pve-storage-id', { + completion => \&PVE::Storage::complete_storage_enabled, + }), filename => { description => "The name of the file to create.", type => 'string', }, - vmid => get_standard_option('pve-vmid', { description => "Specify owner VM" } ), + vmid => get_standard_option('pve-vmid', { + description => "Specify owner VM", + completion => \&PVE::Cluster::complete_vmid, + }), size => { description => "Size in kilobyte (1024 bytes). Optional suffixes 'M' (megabyte, 1024K) and 'G' (gigabyte, 1024M)", type => 'string', diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 7622b1a..3637de2 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -1167,4 +1167,25 @@ sub foreach_volid { } } +# bash completion helper + +sub complete_storage { + my ($cmdname, $pname, $cvalue) = @_; + + return $cmdname eq 'add' ? [] : [ PVE::Storage::storage_ids() ]; +} + +sub complete_storage_enabled { + my ($cmdname, $pname, $cvalue) = @_; + + my $res = []; + + my $cfg = PVE::Storage::config(); + foreach my $sid (keys %{$cfg->{ids}}) { + next if !storage_check_enabled($cfg, $sid, undef, 1); + push @$res, $sid; + } + return $res; +} + 1; diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index a245192..c921174 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -20,7 +20,8 @@ cfs_register_file ('storage.cfg', my $defaultData = { propertyList => { type => { description => "Storage type." }, - storage => get_standard_option('pve-storage-id'), + storage => get_standard_option('pve-storage-id', + { completion => \&PVE::Storage::complete_storage }), nodes => get_standard_option('pve-node-list', { optional => 1 }), content => { description => "Allowed content types. Note: value 'rootdir' is used for Containers, and value 'images' for KVM-Qemu VM's.\n", -- 2.39.2