Synopsis
# in Rexfile or Rex modules
use Rex::Hook::File::Diff;
desc 'write random content to file';
task 'diff_test', sub {
file '/tmp/rex_hook_file_diff', content => rand();
};
# on the CLI
$ rex diff_test
[2020-01-27 19:14:49] INFO - Running task diff_test on <local>
Diff for: /tmp/rex_hook_file_diff
--- /tmp/rex_hook_file_diff Mon Jan 27 19:14:20 2020
+++ /tmp/.rex.tmp.rex_hook_file_diff Mon Jan 27 19:14:49 2020
@@ -1 +1 @@
-0.985874954641066
+0.926667291235379
[2020-01-27 19:14:49] INFO - All tasks successful on all hosts
Description
The linked gist is the initial draft of a module that allows Rex to show diffs on the terminal upon file changes during task execution. I'm posting it here both for early availability and early feedback.
I think it is a good example of how to extend Rex without changing the core, and publishing on CPAN would be a great way to share.
Additional features could include colored output support, and pluggable diff backends (like Text::Diff::Unified::XS, or even using diff
binary, if present).
The name is following this logic: it extends Rex
via a Hook
for File
operations to show the Diff
of changes. It could be more specific (e.g. Rex::Hook::File::Diff::Unified
), but I feel it's already getting long, so I tried to find a good balance.
Some questions I am wondering about:
- is there a better fit for the name?
- would it be possible/easy to merge this into Rex core distribution later (which already has
Rex::Hook
)? - is there a better approach to generate diffs?
Feedback welcome both here and on the gist.
Comments
Please sign up to post a review.