5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-02-04 17:47:17 +03:00

improve bash completions

This commit is contained in:
Dietmar Maurer 2015-09-18 09:33:09 +02:00
parent c669f42d4e
commit f7621c0126
3 changed files with 30 additions and 3 deletions

View File

@ -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',

View File

@ -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;

View File

@ -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",