line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::RunList; |
6
|
|
|
|
|
|
|
|
7
|
102
|
|
|
102
|
|
8882
|
use v5.12.5; |
|
102
|
|
|
|
|
325
|
|
8
|
102
|
|
|
102
|
|
486
|
use warnings; |
|
102
|
|
|
|
|
522
|
|
|
102
|
|
|
|
|
3030
|
|
9
|
|
|
|
|
|
|
|
10
|
102
|
|
|
102
|
|
537
|
use Rex::Logger; |
|
102
|
|
|
|
|
2518
|
|
|
102
|
|
|
|
|
994
|
|
11
|
102
|
|
|
102
|
|
9697
|
use Rex::TaskList; |
|
102
|
|
|
|
|
224
|
|
|
102
|
|
|
|
|
697
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $INSTANCE; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
28
|
|
|
28
|
0
|
106
|
my ( $class, %args ) = @_; |
19
|
28
|
|
|
|
|
138
|
return bless \%args, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# returns a singleton |
23
|
|
|
|
|
|
|
sub instance { |
24
|
40
|
|
|
40
|
0
|
841
|
my $class = shift; |
25
|
40
|
100
|
|
|
|
244
|
return $INSTANCE if $INSTANCE; |
26
|
28
|
|
|
|
|
156
|
$INSTANCE = $class->new(@_); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add_task { |
30
|
101
|
|
|
101
|
0
|
327
|
my ( $self, $task_name, $task_args, $task_opts ) = @_; |
31
|
101
|
|
50
|
|
|
287
|
$task_args ||= []; |
32
|
101
|
|
50
|
|
|
379
|
$task_opts ||= {}; |
33
|
101
|
|
|
|
|
269
|
my $task = $self->task_list->get_task($task_name); |
34
|
101
|
|
|
|
|
513
|
$task->set_args(@$task_args); |
35
|
101
|
|
|
|
|
612
|
$task->set_opts(%$task_opts); |
36
|
101
|
|
|
|
|
210
|
push @{ $self->{tasks} }, $task; |
|
101
|
|
|
|
|
514
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub current_index { |
40
|
5
|
|
|
5
|
0
|
14
|
my ($self) = @_; |
41
|
5
|
|
100
|
|
|
38
|
return $self->{current_index} || 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub increment_current_index { |
45
|
70
|
|
|
70
|
0
|
621
|
my ($self) = @_; |
46
|
70
|
|
|
|
|
1600
|
return $self->{current_index} += 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub current_task { |
50
|
5
|
|
|
5
|
0
|
12
|
my $self = shift; |
51
|
5
|
|
|
|
|
18
|
my $i = $self->current_index; |
52
|
5
|
|
|
|
|
28
|
$self->{tasks}->[$i]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
39
|
50
|
|
39
|
0
|
208
|
sub tasks { @{ shift->{tasks} || [] } } |
|
39
|
|
|
|
|
218
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub task_list { |
58
|
290
|
|
|
290
|
0
|
506
|
my $self = shift; |
59
|
290
|
100
|
|
|
|
1190
|
return $self->{task_list} if $self->{task_list}; |
60
|
28
|
|
|
|
|
134
|
$self->{task_list} = Rex::TaskList->create; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub run_tasks { |
64
|
29
|
|
|
29
|
0
|
215
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
29
|
|
|
|
|
127
|
for my $task ( $self->tasks ) { |
67
|
71
|
|
|
|
|
963
|
Rex::TaskList->run($task); |
68
|
55
|
|
|
|
|
792
|
$self->increment_current_index; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Parse @ARGV to get tasks, task args, and task opts. Use these values to |
73
|
|
|
|
|
|
|
# generate a list of tasks the user wants to run. |
74
|
|
|
|
|
|
|
sub parse_opts { |
75
|
35
|
|
|
35
|
0
|
428
|
my ( $self, @params ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
35
|
100
|
|
|
|
242
|
return $self->pre_1_4_parse_opts(@params) |
78
|
|
|
|
|
|
|
unless Rex::Config->get_task_chaining_cmdline_args; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
86
|
while ( my $task_name = shift @params ) { |
81
|
33
|
50
|
|
|
|
147
|
$self->exit_rex($task_name) unless $self->task_list->is_task($task_name); |
82
|
|
|
|
|
|
|
|
83
|
33
|
|
|
|
|
136
|
my @args; |
84
|
|
|
|
|
|
|
my %opts; |
85
|
|
|
|
|
|
|
|
86
|
33
|
|
|
|
|
102
|
while ( my $param = shift @params ) { |
87
|
88
|
100
|
|
|
|
249
|
if ( $self->task_list->is_task($param) ) { |
88
|
22
|
|
|
|
|
100
|
unshift @params, $param; |
89
|
22
|
|
|
|
|
58
|
last; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
66
|
100
|
|
|
|
580
|
if ( $param =~ /^--/ ) { |
93
|
33
|
|
|
|
|
135
|
my ( $key, $val ) = split /=/, $param, 2; |
94
|
33
|
|
|
|
|
260
|
$key =~ s/^--//; |
95
|
|
|
|
|
|
|
|
96
|
33
|
50
|
|
|
|
268
|
$opts{$key} = defined $val ? $val : 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
33
|
|
|
|
|
120
|
push @args, $param; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
33
|
|
|
|
|
162
|
$self->add_task( $task_name, \@args, \%opts ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
145
|
return $self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# this function is to parse the task parameters in a pre 1.4 fashion. |
110
|
|
|
|
|
|
|
# this is used if the feature flag 'no_task_chaining_cmdline_args' or |
111
|
|
|
|
|
|
|
# '< 1.4' is enabled. |
112
|
|
|
|
|
|
|
sub pre_1_4_parse_opts { |
113
|
24
|
|
|
24
|
0
|
106
|
my ( $self, @params ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#### parse task options |
116
|
24
|
|
|
|
|
48
|
my %task_opts; |
117
|
|
|
|
|
|
|
|
118
|
24
|
|
|
|
|
212
|
for my $p (@params) { |
119
|
104
|
|
|
|
|
366
|
my ( $key, $val ) = split( /=/, $p, 2 ); |
120
|
|
|
|
|
|
|
|
121
|
104
|
|
|
|
|
338
|
$key =~ s/^--//; |
122
|
|
|
|
|
|
|
|
123
|
104
|
100
|
|
|
|
214
|
if ( defined $val ) { $task_opts{$key} = $val; next; } |
|
36
|
|
|
|
|
186
|
|
|
36
|
|
|
|
|
82
|
|
124
|
68
|
|
|
|
|
178
|
$task_opts{$key} = 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
24
|
|
|
|
|
168
|
for my $task_name (@params) { |
128
|
104
|
100
|
66
|
|
|
712
|
next if $task_name =~ m/^\-\-/ || $task_name =~ m/=/; |
129
|
68
|
50
|
|
|
|
260
|
$self->exit_rex($task_name) unless $self->task_list->is_task($task_name); |
130
|
68
|
|
|
|
|
290
|
$self->add_task( $task_name, [], \%task_opts ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub exit_rex { |
135
|
0
|
|
|
0
|
0
|
|
my ( $self, $task_name ) = @_; |
136
|
0
|
|
|
|
|
|
my $msg = "Task names are case sensitive "; |
137
|
0
|
|
|
|
|
|
$msg .= "and the module delimiter is a single colon."; |
138
|
0
|
|
|
|
|
|
Rex::Logger::info( "No task named '$task_name' found. $msg", 'error' ); |
139
|
0
|
|
|
|
|
|
Rex::CLI::exit_rex(1); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |