line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optargs; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
3
|
use OptArgs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
145
|
use lib 'lib'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.21'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$OptArgs::COLOUR = 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
arg class => ( |
11
|
|
|
|
|
|
|
isa => 'Str', |
12
|
|
|
|
|
|
|
required => 1, |
13
|
|
|
|
|
|
|
comment => 'OptArgs-based module to load', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
arg name => ( |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
comment => 'Name of the command', |
19
|
|
|
|
|
|
|
default => sub { '' } |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
opt indent => ( |
23
|
|
|
|
|
|
|
isa => 'Int', |
24
|
|
|
|
|
|
|
comment => 'Number of spaces to indent sub-commands', |
25
|
|
|
|
|
|
|
alias => 'i', |
26
|
|
|
|
|
|
|
default => 4, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
opt spacer => ( |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
comment => 'Character to use for indent spaces', |
32
|
|
|
|
|
|
|
default => ' ', |
33
|
|
|
|
|
|
|
alias => 's', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
opt full => ( |
37
|
|
|
|
|
|
|
isa => 'Bool', |
38
|
|
|
|
|
|
|
comment => 'Print the full usage messages', |
39
|
|
|
|
|
|
|
alias => 'f', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub run { |
43
|
4
|
|
|
4
|
1
|
6
|
my $opts = shift; |
44
|
|
|
|
|
|
|
|
45
|
4
|
50
|
|
|
|
178
|
die $@ unless eval "require $opts->{class};"; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
41
|
my $initial = do { my @tmp = split( /::/, $opts->{class} ) }; |
|
4
|
|
|
|
|
15
|
|
48
|
4
|
|
|
|
|
8
|
my $indent = $opts->{spacer} x $opts->{indent}; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
4
|
binmode( STDOUT, ':encoding(utf8)' ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
56
|
|
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
949
|
foreach my $cmd ( OptArgs::_cmdlist() ) { |
53
|
32
|
|
|
|
|
38
|
my $length = do { my @tmp = split( /::/, $cmd ) } |
|
32
|
|
|
|
|
124
|
|
54
|
|
|
|
|
|
|
- $initial; |
55
|
32
|
|
|
|
|
59
|
my $space = $indent x $length; |
56
|
|
|
|
|
|
|
|
57
|
32
|
50
|
|
|
|
61
|
unless ( $opts->{full} ) { |
58
|
32
|
|
|
|
|
78
|
my $usage = OptArgs::_synopsis($cmd); |
59
|
32
|
|
|
|
|
131
|
$usage =~ s/^usage: \S+/$space$opts->{name}/; |
60
|
32
|
|
|
|
|
629
|
print $usage; |
61
|
32
|
|
|
|
|
142
|
next; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $usage = OptArgs::_usage($cmd); |
65
|
0
|
|
|
|
|
|
$usage =~ s/^usage: \S+/usage: $opts->{name}/; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $n = 79 - length $space; |
68
|
0
|
|
|
|
|
|
print $space, '#' x $n, "\n"; |
69
|
0
|
|
|
|
|
|
print $space, "# $cmd\n"; |
70
|
0
|
|
|
|
|
|
print $space, '#' x $n, "\n"; |
71
|
0
|
|
|
|
|
|
$usage =~ s/^/$space/gm; |
72
|
0
|
|
|
|
|
|
print $usage; |
73
|
0
|
|
|
|
|
|
print $space . "\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |