-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #1066 - use Task::run() method to call the task code.
- Loading branch information
Showing
1 changed file
with
32 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# | ||
|
||
# (c) Jan Gehring <[email protected]> | ||
# | ||
# vim: set ts=2 sw=2 tw=0: | ||
|
@@ -1011,16 +1011,22 @@ sub needs { | |
} | ||
|
||
if ( $self eq "main" ) { | ||
$self = "Rex::CLI"; | ||
$self = ""; # Tasks in main namespace are really registered in Rex::CLI | ||
} | ||
|
||
no strict 'refs'; | ||
my @maybe_tasks_to_run = @{"${self}::tasks"}; | ||
use strict; | ||
my $tl = Rex::TaskList->create(); | ||
my @maybe_tasks_to_run; | ||
if($self) { | ||
@maybe_tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$}); | ||
} | ||
else { | ||
@maybe_tasks_to_run = $tl->get_all_tasks(qr{^[A-Za-z0-9_\-]+$}); | ||
} | ||
|
||
if ( !@args && !@maybe_tasks_to_run ) { | ||
@args = ($self); | ||
($self) = caller; | ||
$self = "" if($self =~ m/^(Rex::CLI|main)$/); | ||
} | ||
|
||
if ( ref( $args[0] ) eq "ARRAY" ) { | ||
|
@@ -1029,24 +1035,36 @@ sub needs { | |
|
||
Rex::Logger::debug("need to call tasks from $self"); | ||
|
||
no strict 'refs'; | ||
my @tasks_to_run = @{"${self}::tasks"}; | ||
use strict; | ||
my @tasks_to_run; | ||
if($self) { | ||
@tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$}); | ||
} | ||
else { | ||
@tasks_to_run = $tl->get_all_tasks(qr{^[A-Za-z0-9_\-]+$}); | ||
} | ||
|
||
my $run_list = Rex::RunList->instance; | ||
my $current_task = $run_list->current_task; | ||
my %task_opts = $current_task->get_opts; | ||
my @task_args = $current_task->get_args; | ||
|
||
if($self) { | ||
my $suffix = $self; | ||
$suffix =~ s/::/:/g; | ||
@args = map { $_ = "$suffix:$_" } @args; | ||
} | ||
|
||
for my $task (@tasks_to_run) { | ||
my $task_name = $task->{"name"}; | ||
if ( @args && grep ( /^$task_name$/, @args ) ) { | ||
Rex::Logger::debug( "Calling " . $task->{"name"} ); | ||
$task->{"code"}->( \%task_opts, \@task_args ); | ||
my $task_o = $tl->get_task($task); | ||
my $task_name = $task_o->name; | ||
my $suffix = $self . ":"; | ||
if ( @args && grep ( /^\Q$task_name\E$/, @args ) ) { | ||
Rex::Logger::debug( "Calling " . $task_o->name ); | ||
$task_o->run( "<func>", params => \@task_args, args => \%task_opts ); | ||
} | ||
elsif ( !@args ) { | ||
Rex::Logger::debug( "Calling " . $task->{"name"} ); | ||
$task->{"code"}->( \%task_opts, \@task_args ); | ||
Rex::Logger::debug( "Calling " . $task_o->name ); | ||
$task_o->run( "<func>", params => \@task_args, args => \%task_opts ); | ||
} | ||
} | ||
|
||
|