line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::CLI; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
150874
|
use Catmandu::Sane; |
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
117
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
103
|
use Catmandu::Util qw(is_instance); |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
645
|
|
8
|
14
|
|
|
14
|
|
644
|
use Catmandu; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
86
|
|
9
|
14
|
|
|
14
|
|
9398
|
use Log::Any::Adapter; |
|
14
|
|
|
|
|
5497
|
|
|
14
|
|
|
|
|
62
|
|
10
|
14
|
|
|
14
|
|
434
|
use Data::Dumper; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
758
|
|
11
|
|
|
|
|
|
|
|
12
|
14
|
|
|
14
|
|
85
|
use parent qw(App::Cmd); |
|
14
|
|
|
|
|
87
|
|
|
14
|
|
|
|
|
79
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub deleted_commands { |
15
|
|
|
|
|
|
|
[ |
16
|
624
|
|
|
624
|
0
|
1945
|
qw( |
17
|
|
|
|
|
|
|
Catmandu::Cmd::data |
18
|
|
|
|
|
|
|
Catmandu::Cmd::exporter_info |
19
|
|
|
|
|
|
|
Catmandu::Cmd::fix_info |
20
|
|
|
|
|
|
|
Catmandu::Cmd::importer_info |
21
|
|
|
|
|
|
|
Catmandu::Cmd::module_info |
22
|
|
|
|
|
|
|
Catmandu::Cmd::move |
23
|
|
|
|
|
|
|
Catmandu::Cmd::store_info |
24
|
|
|
|
|
|
|
) |
25
|
|
|
|
|
|
|
]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
1
|
1174
|
sub default_command {'commands'} |
29
|
|
|
|
|
|
|
|
30
|
14
|
|
|
14
|
1
|
15350
|
sub plugin_search_path {'Catmandu::Cmd'} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub global_opt_spec { |
33
|
141
|
|
|
141
|
1
|
9965
|
(['debug|D:i', ""], ['load_path|L=s@', ""], ['lib_path|I=s@', ""]); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub default_log4perl_config { |
37
|
2
|
|
50
|
2
|
0
|
9
|
my $level = shift // 'DEBUG'; |
38
|
2
|
|
50
|
|
|
8
|
my $appender = shift // 'STDERR'; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
14
|
my $config = <<EOF; |
41
|
|
|
|
|
|
|
log4perl.category.Catmandu=$level,$appender |
42
|
|
|
|
|
|
|
log4perl.category.Catmandu::Fix::log=TRACE,$appender |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
log4perl.appender.STDOUT=Log::Log4perl::Appender::Screen |
45
|
|
|
|
|
|
|
log4perl.appender.STDOUT.stderr=0 |
46
|
|
|
|
|
|
|
log4perl.appender.STDOUT.utf8=1 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
log4perl.appender.STDOUT.layout=PatternLayout |
49
|
|
|
|
|
|
|
log4perl.appender.STDOUT.layout.ConversionPattern=%d [%P] - %p %l %M time=%r : %m%n |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
log4perl.appender.STDERR=Log::Log4perl::Appender::Screen |
52
|
|
|
|
|
|
|
log4perl.appender.STDERR.stderr=1 |
53
|
|
|
|
|
|
|
log4perl.appender.STDERR.utf8=1 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
log4perl.appender.STDERR.layout=PatternLayout |
56
|
|
|
|
|
|
|
log4perl.appender.STDERR.layout.ConversionPattern=%d [%P] - %l : %m%n |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
EOF |
59
|
2
|
|
|
|
|
12
|
\$config; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub setup_debugging { |
63
|
4
|
|
|
4
|
0
|
24
|
my %LEVELS = (1 => 'WARN', 2 => 'INFO', 3 => 'DEBUG'); |
64
|
4
|
|
|
|
|
9
|
my $debug = shift; |
65
|
4
|
|
100
|
|
|
20
|
my $level = $LEVELS{$debug} // 'WARN'; |
66
|
4
|
|
|
|
|
9
|
my $load_from; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
try { |
69
|
4
|
|
|
4
|
|
347
|
my $log4perl_pkg = Catmandu::Util::require_package('Log::Log4perl'); |
70
|
4
|
|
|
|
|
12
|
my $logany_adapter |
71
|
|
|
|
|
|
|
= Catmandu::Util::require_package('Log::Any::Adapter::Log4perl'); |
72
|
4
|
|
|
|
|
29
|
my $config = Catmandu->config->{log4perl}; |
73
|
|
|
|
|
|
|
|
74
|
4
|
100
|
|
|
|
14
|
if (defined $config) { |
75
|
2
|
100
|
|
|
|
22
|
if ($config =~ /^\S+$/) { |
76
|
1
|
|
|
|
|
5
|
Log::Log4perl::init($config); |
77
|
1
|
|
|
|
|
8198
|
$load_from = "file: $config"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
1
|
|
|
|
|
16
|
Log::Log4perl::init(\$config); |
81
|
1
|
|
|
|
|
6723
|
$load_from = "string: <defined in catmandu.yml>"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
2
|
|
|
|
|
11
|
Log::Log4perl::init(default_log4perl_config($level, 'STDERR')); |
86
|
2
|
|
|
|
|
15512
|
$load_from = "string: <defined in " . __PACKAGE__ . ">"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
4
|
|
|
|
|
41
|
Log::Any::Adapter->set('Log4perl'); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
catch { |
92
|
0
|
|
|
0
|
|
0
|
print STDERR <<EOF; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Oops! Debugging tools not available on this platform |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Try to install Log::Log4perl and Log::Any::Adapter::Log4perl |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Hint: cpan Log::Log4perl Log::Any::Adapter::Log4perl |
99
|
|
|
|
|
|
|
EOF |
100
|
0
|
|
|
|
|
0
|
exit(2); |
101
|
4
|
|
|
|
|
83
|
}; |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
2990
|
Catmandu->log->warn( |
104
|
|
|
|
|
|
|
"debug activated - level $level - config load from $load_from"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# overload run to read the global options before |
108
|
|
|
|
|
|
|
# the App::Cmd object is created |
109
|
|
|
|
|
|
|
sub run { |
110
|
48
|
|
|
48
|
1
|
101100
|
my ($class) = @_; |
111
|
|
|
|
|
|
|
|
112
|
48
|
|
|
|
|
370
|
my ($global_opts, $argv) |
113
|
|
|
|
|
|
|
= $class->_process_args([@ARGV], |
114
|
|
|
|
|
|
|
$class->_global_option_processing_params); |
115
|
|
|
|
|
|
|
|
116
|
48
|
|
50
|
|
|
399890
|
my $load_path = $global_opts->{load_path} || []; |
117
|
48
|
|
100
|
|
|
273
|
my $lib_path = $global_opts->{lib_path} || []; |
118
|
|
|
|
|
|
|
|
119
|
48
|
100
|
|
|
|
246
|
if (exists $global_opts->{debug}) { |
120
|
4
|
|
50
|
|
|
23
|
setup_debugging($global_opts->{debug} // 1); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
48
|
100
|
|
|
|
2675
|
if (@$lib_path) { |
124
|
2
|
|
|
|
|
12
|
Catmandu::Util::use_lib(@$lib_path); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
48
|
|
|
|
|
395
|
Catmandu->load(@$load_path); |
128
|
|
|
|
|
|
|
|
129
|
48
|
50
|
|
|
|
228
|
my $self = ref $class ? $class : $class->new; |
130
|
48
|
|
|
|
|
387
|
$self->set_global_options($global_opts); |
131
|
48
|
|
|
|
|
498
|
my ($cmd, $opts, @args) = $self->prepare_command(@$argv); |
132
|
|
|
|
|
|
|
|
133
|
48
|
|
|
|
|
119992
|
my $err; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
try { |
136
|
48
|
|
|
48
|
|
4980
|
$self->execute_command($cmd, $opts, @args); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
catch { |
139
|
8
|
|
|
8
|
|
1719
|
my $e = $_; |
140
|
8
|
100
|
100
|
|
|
41
|
if (is_instance($e, 'Catmandu::NoSuchPackage') |
|
|
50
|
|
|
|
|
|
141
|
|
|
|
|
|
|
&& $e->package_name eq 'Catmandu::Importer::help') |
142
|
|
|
|
|
|
|
{ |
143
|
1
|
|
|
|
|
39
|
$err = "Did you mean 'catmandu $ARGV[1] $ARGV[0]'?"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif (is_instance($e, 'Catmandu::Error')) { |
146
|
7
|
|
|
|
|
54
|
$err = $e->log_message; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
0
|
|
|
|
|
0
|
$err = $e; |
150
|
|
|
|
|
|
|
} |
151
|
48
|
|
|
|
|
600
|
}; |
152
|
|
|
|
|
|
|
|
153
|
48
|
100
|
|
|
|
91021
|
if (defined $err) { |
154
|
8
|
|
|
|
|
68
|
say STDERR "Oops! $err"; |
155
|
8
|
|
|
|
|
531
|
return; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
40
|
|
|
|
|
1338
|
1; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub should_ignore { |
162
|
624
|
|
|
624
|
0
|
90175
|
my ($self, $cmd_class) = @_; |
163
|
624
|
|
|
|
|
936
|
for my $cmd (@{$self->deleted_commands}) { |
|
624
|
|
|
|
|
1248
|
|
164
|
4368
|
50
|
|
|
|
16943
|
return 1 if $cmd_class->isa($cmd); |
165
|
|
|
|
|
|
|
} |
166
|
624
|
|
|
|
|
1512
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=pod |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 NAME |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Catmandu::CLI - The App::Cmd application class for the catmandu command line script |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 SEE ALSO |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L<catmandu> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |