]> git.proxmox.com Git - pve-storage.git/commitdiff
improve bash completions
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 18 Sep 2015 07:33:09 +0000 (09:33 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 18 Sep 2015 07:33:09 +0000 (09:33 +0200)
PVE/API2/Storage/Content.pm
PVE/Storage.pm
PVE/Storage/Plugin.pm

index 1b09f53e03d9e384bd2f1b3fb9ce5be13127c31f..a7e9fe3be0ceb75edaf37ac88f64f863b033f60d 100644 (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',
index 7622b1a53634719853d05772c537deeda2ed15bd..3637de205bede0fad45b4423b0e3de9ddd985765 100755 (executable)
@@ -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;
index a2451920bdf1e37b28d2969f51f46677c551d25c..c921174fac78730e4d016fdfb98196052984cb06 100644 (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",