line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dyer::CLI; |
2
|
1
|
|
|
1
|
|
19166
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
88
|
|
4
|
1
|
|
|
1
|
|
5
|
use Cwd; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
59
|
|
5
|
1
|
|
|
1
|
|
2404
|
use Getopt::Std; |
|
1
|
|
|
|
|
45
|
|
|
1
|
|
|
|
|
967
|
|
6
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)/g; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$main::DEBUG=1; |
10
|
|
|
|
|
|
|
$main::VERBOSE=1; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub main::DEBUG { |
13
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
14
|
0
|
0
|
|
|
|
0
|
if (defined $val){ |
15
|
0
|
|
|
|
|
0
|
$main::DEBUG = $val; |
16
|
|
|
|
|
|
|
} |
17
|
0
|
|
|
|
|
0
|
return $main::DEBUG; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub main::VERBOSE { |
21
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
22
|
0
|
0
|
|
|
|
0
|
if (defined $val){ |
23
|
0
|
|
|
|
|
0
|
$main::VERBOSE = $val; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
0
|
return $main::VERBOSE; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub main::force_root { |
37
|
0
|
|
|
0
|
|
0
|
my $whoami = `whoami`; |
38
|
0
|
|
|
|
|
0
|
chomp $whoami; |
39
|
0
|
0
|
0
|
|
|
0
|
$whoami eq 'root' or print "$0, only root can use this." and exit; |
40
|
0
|
|
|
|
|
0
|
return 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub main::gopts { |
44
|
0
|
|
|
0
|
|
0
|
my $opts = shift; |
45
|
0
|
|
0
|
|
|
0
|
$opts||=''; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
0
|
if($opts=~s/v\:?|h\:?//sg){ |
48
|
0
|
0
|
|
|
|
0
|
print STDERR("$0, options changed") if ::DEBUG; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$opts.='vh'; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $o = {}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
Getopt::Std::getopts($opts, $o); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
if($o->{v}){ |
58
|
0
|
0
|
|
|
|
0
|
if (defined $::VERSION){ |
59
|
0
|
|
|
|
|
0
|
print $::VERSION; |
60
|
0
|
|
|
|
|
0
|
exit; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
0
|
print STDERR "$0 has no version\n"; |
63
|
0
|
|
|
|
|
0
|
exit; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
if($o->{h}){ |
68
|
0
|
|
|
|
|
0
|
main::man() |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
return $o; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub main::man { |
75
|
0
|
|
|
0
|
|
0
|
my $name = main::_scriptname(); |
76
|
0
|
0
|
|
|
|
0
|
print `man $name` and exit; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub main::_scriptname{ |
80
|
1
|
50
|
|
1
|
|
11
|
my $name = $0 or return; |
81
|
1
|
|
|
|
|
9
|
$name=~s/^.+\///; |
82
|
1
|
|
|
|
|
10
|
return $name; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub main::argv_aspaths { |
86
|
0
|
|
|
0
|
|
|
my @argv; |
87
|
0
|
0
|
|
|
|
|
scalar @ARGV or return; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
for(@ARGV){ |
90
|
0
|
0
|
0
|
|
|
|
my $abs = Cwd::abs_path($_) or warn("$0, Does not resolve: $_, skipped.") and next; |
91
|
0
|
0
|
0
|
|
|
|
-e $abs or warn("$0, Does not exist: $_, skipped.") and next; |
92
|
0
|
|
|
|
|
|
push @argv, $abs; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
scalar @argv or return; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return \@argv; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub main::argv_aspaths_strict { |
101
|
0
|
|
|
0
|
|
|
my @argv; |
102
|
0
|
0
|
|
|
|
|
scalar @ARGV or return; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
for(@ARGV){ |
105
|
0
|
0
|
0
|
|
|
|
my $abs = Cwd::abs_path($_) or warn("Does not resolve: $_.") and return; |
106
|
0
|
0
|
0
|
|
|
|
-e $abs or warn("Is not on disk: $_.") and return; |
107
|
0
|
|
|
|
|
|
push @argv, $abs; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
0
|
|
|
|
|
scalar @argv or return; |
110
|
0
|
|
|
|
|
|
return \@argv; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub main::argv_aspaths_loose { |
114
|
0
|
|
|
0
|
|
|
my @argv; |
115
|
0
|
0
|
|
|
|
|
scalar @ARGV or return; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
for(@ARGV){ |
118
|
0
|
0
|
0
|
|
|
|
my $abs = Cwd::abs_path($_) or warn("$0, Does not resolve: $_, skipped.") and next; |
119
|
0
|
|
|
|
|
|
push @argv, $abs; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
0
|
|
|
|
|
scalar @argv or return; |
122
|
0
|
|
|
|
|
|
return \@argv; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub main::yn { |
127
|
0
|
|
0
|
0
|
|
|
my $question = shift; $question ||='Your answer? '; |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $val = undef; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
until (defined $val){ |
131
|
0
|
|
|
|
|
|
print "$question (y/n): "; |
132
|
0
|
|
|
|
|
|
$val = ; |
133
|
0
|
|
|
|
|
|
chomp $val; |
134
|
0
|
0
|
|
|
|
|
if ($val eq 'y'){ $val = 1; } |
|
0
|
0
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
elsif ($val eq 'n'){ $val = 0;} |
136
|
0
|
|
|
|
|
|
else { $val = undef; } |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
return $val; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |