]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/CLI/pvesm.pm
pvesm list: right align size column
[pve-storage.git] / PVE / CLI / pvesm.pm
index 01ddd23c026787a4ca9f7a6e9d42232c50c73f3b..510faba0882bd43d7f1ef1f85498e2768777a89f 100755 (executable)
@@ -117,28 +117,30 @@ __PACKAGE__->register_method ({
 my $print_content = sub {
     my ($list) = @_;
 
-    my $maxlenname = 0;
+    my ($maxlenname, $maxsize) = (0, 0);
     foreach my $info (@$list) {
-
        my $volid = $info->{volid};
        my $sidlen =  length ($volid);
        $maxlenname = $sidlen if $sidlen > $maxlenname;
+       $maxsize = $info->{size} if ($info->{size} // 0) > $maxsize;
     }
+    my $sizemaxdigits = length($maxsize);
+
+    my $basefmt = "%-${maxlenname}s %-7s %-9s %${sizemaxdigits}s";
+    printf "$basefmt %s\n", "Volid", "Format", "Type", "Size", "VMID";
 
     foreach my $info (@$list) {
        next if !$info->{vmid};
        my $volid = $info->{volid};
 
-       printf "%-${maxlenname}s %5s %10d %d\n", $volid,
-       $info->{format}, $info->{size}, $info->{vmid};
+       printf "$basefmt %d\n", $volid, $info->{format}, $info->{content}, $info->{size}, $info->{vmid};
     }
 
     foreach my $info (sort { $a->{format} cmp $b->{format} } @$list) {
        next if $info->{vmid};
        my $volid = $info->{volid};
 
-       printf "%-${maxlenname}s %5s %10d\n", $volid,
-       $info->{format}, $info->{size};
+       printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $info->{size};
     }
 };
 
@@ -506,7 +508,7 @@ __PACKAGE__->register_method ({
        type => 'array',
        items => {
            type => "object",
-           properties => { 
+           properties => {
                volname => {
                    description => "The volume name.",
                    type => 'string',