mirror of https://github.com/digint/btrbk
btrbk: add print_size, and command line option modifier
parent
075fb8bfad
commit
3094092df4
26
btrbk
26
btrbk
|
@ -275,6 +275,7 @@ my $do_dumper;
|
|||
my $show_progress = 0;
|
||||
my $err = "";
|
||||
my $output_format;
|
||||
my @output_unit;
|
||||
my $lockfile;
|
||||
my $tlog_fh;
|
||||
my $syslog_enabled = 0;
|
||||
|
@ -4671,6 +4672,27 @@ sub print_formatted(@)
|
|||
}
|
||||
|
||||
|
||||
sub print_size($)
|
||||
{
|
||||
my $size = shift;
|
||||
if($output_format && ($output_format eq "raw")) {
|
||||
return $size;
|
||||
}
|
||||
return "-" if($size == 0);
|
||||
my ($unit, $mul);
|
||||
if(@output_unit) {
|
||||
($unit, $mul) = @output_unit;
|
||||
}
|
||||
else {
|
||||
($unit, $mul) = ("KiB", 1024);
|
||||
($unit, $mul) = ("MiB", $mul * 1024) if($size > $mul * 1024);
|
||||
($unit, $mul) = ("GiB", $mul * 1024) if($size > $mul * 1024);
|
||||
($unit, $mul) = ("TiB", $mul * 1024) if($size > $mul * 1024);
|
||||
}
|
||||
return sprintf('%.2f', ($size / $mul)) . " $unit";
|
||||
}
|
||||
|
||||
|
||||
sub _origin_tree
|
||||
{
|
||||
my $prefix = shift;
|
||||
|
@ -4806,6 +4828,10 @@ MAIN:
|
|||
'print-schedule|S' => \$print_schedule,
|
||||
'lockfile=s' => \$lockfile_cmdline,
|
||||
'override=s' => \@config_override_cmdline, # e.g. --override=incremental=no
|
||||
'kbytes' => sub { @output_unit = ("KiB", 1024 ) },
|
||||
'mbytes' => sub { @output_unit = ("MiB", 1024 * 1024 ) },
|
||||
'gbytes' => sub { @output_unit = ("GiB", 1024 * 1024 * 1024 ) },
|
||||
'tbytes' => sub { @output_unit = ("TiB", 1024 * 1024 * 1024 * 1024 ) },
|
||||
))
|
||||
{
|
||||
VERSION_MESSAGE();
|
||||
|
|
Loading…
Reference in New Issue