1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#!/usr/bin/perl
use strict;
use Pod::Usage;
use Pod::Man;
use Pod::Find qw(pod_where);
use File::Basename;
use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order auto_version);
use Unix::Sysexits;
use Data::Dumper;
my $progname = basename($0);
my $progdescr = 'backup manager';
my %args;
our $VERSION = '1.6.90';
=head1 NAME
beam - backup manager
=head1 SYNOPSIS
B<beam>
[B<-dn>]
[B<-f> I<FILE>]
[B<--config-file=>I<FILE>
[B<--debug>]
[B<--dry-run>]
I<COMMAND> [I<ARGS>]
B<beam> B<-h> | B<--help> | B<--usage> | B<--version>
=cut
sub pod_usage_msg {
my ($obj) = @_;
my %args;
open my $fd, '>', \my $msg;
$args{-input} = pod_where({-inc => 1}, ref($obj)) if defined $obj;
pod2usage(-verbose => 99,
-sections => 'NAME',
-output => $fd,
-exitval => 'NOEXIT',
%args);
my @a = split /\n/, $msg;
$msg = $a[1];
$msg =~ s/^\s+//;
$msg =~ s/ - /: /;
return $msg;
}
GetOptions("h" => sub {
pod2usage(-message => pod_usage_msg(),
-exitstatus => EX_OK);
},
"help" => sub {
pod2usage(-exitstatus => EX_OK, -verbose => 2);
},
"usage" => sub {
pod2usage(-exitstatus => EX_OK, -verbose => 0);
},
"debug|d" => sub { $args{debug}++ },
"dry-run|n" => sub { $args{dry_run} = 1 },
"config-file|f=s" => sub { $args{config} = $_[1] }
) or exit(EX_USAGE);
unless (@ARGV) {
print STDERR "$progname: no command name\n";
exit(EX_USAGE);
}
my %ctab = (
backup => sub {
use App::Beam::Backup;
return new App::Beam::Backup(@_);
},
restore => sub {
use App::Beam::Restore;
return new App::Beam::Restore(@_);
},
list => sub {
use App::Beam::List;
return new App::Beam::List(@_);
}
);
my $command = shift;
unless (defined($ctab{$command})) {
print STDERR "$progname: no such command\n";
exit(EX_USAGE);
}
my $beam = $ctab{$command}(%args);
Getopt::Long::Configure('pass_through');
GetOptions("h" => sub {
pod2usage(-message => pod_usage_msg($beam),
-input => pod_where({-inc => 1}, ref($beam)),
-exitstatus => EX_OK);
},
"help" => sub {
pod2usage(-input => pod_where({-inc => 1}, ref($beam)),
-exitstatus => EX_OK,
-verbose => 2);
},
"usage" => sub {
pod2usage(-input => pod_where({-inc => 1}, ref($beam)),
-exitstatus => EX_OK,
-verbose => 0);
});
Getopt::Long::Configure('no_pass_through');
$beam->begin;
$beam->run(@ARGV);
$beam->end;
|