Hi David,
On 2020-05-29 18:58, David Woodyard wrote:
>This worked as I needed. Three items, however:
thanks for the feedback, I'm glad it worked for you.
>
>1) The output from the line 'p %results_for;' is in color even though I used
>the -m on the command line. Yellow on white background is very hard to read.
That is because the function `p` (which prints the content of the data
structure) belongs to Data::Printer, and not to Rex. Please see its own
documentation on how to customize its output, including colorization:
https://metacpan.org/pod/Data::Printer
Alternatively, it might also be possible to strip terminal color codes
in a shell pipeline: `rex my_task | strip color codes here`, but that
sounds less ideal.
>Redirecting to a file does not capture the output from the 'p %results_for;'
>line.
Again, that's because Data::Printer prints to STDERR by default
(
https://metacpan.org/pod/Data::Printer#Changing-output-targets). You
can either configure it to print somewhere else, or you can redirect
both STDERR and STDOUT of Rex output to your file.
>Are there any options to print the results using a different method or make
>output monochrome or another color?
I simply used Data::Printer in my examples simply because I prefer that,
but please note that Rex code is just Perl code. Therefore apart from
configuring Data::Printer according to your exact needs, of course you
may use any other perl function or module to print the contents.
>
>2) I use $TASK = $ARGV[0] to get the task I am running. Then changed the
>line:
>after_task_finished 'status_line' => sub {
>to
>after_task_finished "$TASK" => sub {
>And that worked.
>Any issues with using a variable for the task name that would cause a
>problem?
That's an interesting take I haven't seen before, and I think it's a
good example of Rex's versatility. I believe the original intent here is
"please execute this hook after any task".
For that, the documentation of `after_task_finished` I linked earlier
(
https://metacpan.org/pod/Rex::Commands#after_task_finished) mentions,
that the special task name 'ALL' can be used to run code after all tasks
(or the task name can be a regular expression matching the tasks where
you need to attach the hook). I think I would use that, instead of
dynamically attaching the hook to whatever I run currently.
Either way, Rex is friendly, so trusts you to be the one who knows what
approach fits your use case best. So as long as it works for you, that's
your solution :)
>
>3) I assume that the 'after_task_finished' code can be placed anywhere,
>correct?
The `after_task_finished` docs
(
https://metacpan.org/pod/Rex::Commands#after_task_finished) say that
"Please note, this must come after the definition of the specified
task."
Hope this helps, and should you need further support, please consider
joining the community discussion via IRC (Freenode #rex, or
https://kiwiirc.com/nextclient/#irc://irc.freenode.net/#rex?nick=mc-guest-?).
Cheers,
FErki