mirror of
https://github.com/speed47/btrfs-list
synced 2024-09-30 04:43:31 +00:00
feat: add --version
This commit is contained in:
parent
139aed1f73
commit
6a1c5b1e4c
30
btrfs-list
30
btrfs-list
|
@ -18,12 +18,15 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use version;
|
use version;
|
||||||
|
use File::Basename;
|
||||||
use IPC::Open3;
|
use IPC::Open3;
|
||||||
use Symbol 'gensym';
|
use Symbol 'gensym';
|
||||||
use Getopt::Long qw{ :config gnu_getopt no_ignore_case };
|
use Getopt::Long qw{ :config gnu_getopt no_ignore_case };
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Term::ANSIColor;
|
use Term::ANSIColor;
|
||||||
|
|
||||||
|
my $VERSION = "2.0";
|
||||||
|
|
||||||
$Data::Dumper::Sortkeys = 1;
|
$Data::Dumper::Sortkeys = 1;
|
||||||
$Data::Dumper::Terse = 1;
|
$Data::Dumper::Terse = 1;
|
||||||
use constant KiB => 1024**1;
|
use constant KiB => 1024**1;
|
||||||
|
@ -48,6 +51,7 @@ If no [mountpoint] is specified, display info for all btrfs filesystems.
|
||||||
-h, --help display this message
|
-h, --help display this message
|
||||||
--debug enable debug output
|
--debug enable debug output
|
||||||
-q, --quiet silence the quota disabled & quota rescan warnings
|
-q, --quiet silence the quota disabled & quota rescan warnings
|
||||||
|
--version display version info
|
||||||
--color=WHEN colorize the output; WHEN can be 'never',
|
--color=WHEN colorize the output; WHEN can be 'never',
|
||||||
'always', or 'auto' (default is:
|
'always', or 'auto' (default is:
|
||||||
colorize if STDOUT is a term)
|
colorize if STDOUT is a term)
|
||||||
|
@ -94,7 +98,8 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
'debug', => \my $opt_debug,
|
'debug' => \my $opt_debug,
|
||||||
|
'version' => \my $opt_version,
|
||||||
'q|quiet' => \my $opt_quiet,
|
'q|quiet' => \my $opt_quiet,
|
||||||
's|hide-snap' => \my $opt_hide_snapshots,
|
's|hide-snap' => \my $opt_hide_snapshots,
|
||||||
'S|snap-only' => \my $opt_only_snapshots,
|
'S|snap-only' => \my $opt_only_snapshots,
|
||||||
|
@ -246,6 +251,29 @@ sub human2raw {
|
||||||
|
|
||||||
# MAIN
|
# MAIN
|
||||||
|
|
||||||
|
if ($opt_version) {
|
||||||
|
|
||||||
|
# if we were git clone'd, adjust VERSION
|
||||||
|
my $ver = $VERSION;
|
||||||
|
my $dir = dirname($0);
|
||||||
|
if (-d "$dir/.git") {
|
||||||
|
my $cmd = run_cmd(silent_stderr => 1, cmd => [qw{ git -C }, $dir, qw{ describe --tags --dirty }]);
|
||||||
|
if ($cmd->{status} eq 0 && $cmd->{stdout}) {
|
||||||
|
$ver = $cmd->{stdout}[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# also get btrfs --version
|
||||||
|
my $btrfsver;
|
||||||
|
my $cmd = run_cmd(cmd => [qw{ btrfs --version }]);
|
||||||
|
if ($cmd->{status} eq 0) {
|
||||||
|
($btrfsver) = $cmd->{stdout}->[0] =~ /v([0-9.]+)/;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "btrfs-list v$ver using btrfs v$btrfsver\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
# check opts
|
# check opts
|
||||||
|
|
||||||
$opt_color = 'never' if $opt_no_color;
|
$opt_color = 'never' if $opt_no_color;
|
||||||
|
|
Loading…
Reference in a new issue