Revision fd6e2de4
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
scripts/rose_auto_create_model.pl | ||
---|---|---|
129 | 129 |
my $file_exists = -f $meta_file; |
130 | 130 |
if ($file_exists) { |
131 | 131 |
my $old_size = -s $meta_file; |
132 |
my $old_md5 = md5_hex(do { local(@ARGV, $/) = ($meta_file); <> }); |
|
132 |
my $orig_file = do { local(@ARGV, $/) = ($meta_file); <> }; |
|
133 |
my $old_md5 = md5_hex($orig_file); |
|
133 | 134 |
my $new_size = length $full_definition; |
134 | 135 |
my $new_md5 = md5_hex($full_definition); |
135 | 136 |
if ($old_size == $new_size && $old_md5 == $new_md5) { |
136 | 137 |
notice("No changes in $meta_file, skipping.") if $config{verbose}; |
137 | 138 |
return; |
138 | 139 |
} |
140 |
|
|
141 |
show_diff(\$orig_file, \$full_definition) if $config{show_diff}; |
|
139 | 142 |
} |
140 | 143 |
|
141 | 144 |
if (!$config{nocommit}) { |
... | ... | |
162 | 165 |
all => \ my $all, |
163 | 166 |
sugar => \ my $sugar, |
164 | 167 |
'no-commit' => \ my $nocommit, |
168 |
'dry-run' => \ my $nocommit, |
|
165 | 169 |
help => sub { pod2usage(verbose => 99, sections => 'NAME|SYNOPSIS|OPTIONS') }, |
166 | 170 |
verbose => \ my $verbose, |
171 |
diff => \ my $diff, |
|
167 | 172 |
); |
168 | 173 |
|
169 | 174 |
$options->{login} = $login if $login; |
... | ... | |
171 | 176 |
$options->{all} = $all; |
172 | 177 |
$options->{nocommit} = $nocommit; |
173 | 178 |
$options->{verbose} = $verbose; |
179 |
|
|
180 |
if ($diff) { |
|
181 |
if (eval { require Text::Diff; 1 }) { |
|
182 |
$options->{show_diff} = 1; |
|
183 |
} else { |
|
184 |
error('Could not load Text::Diff. Sorry, no diffs for you.'); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
sub show_diff { |
|
190 |
my ($text_a, $text_b) = @_; |
|
191 |
|
|
192 |
my %colors = ( |
|
193 |
'+' => 'green', |
|
194 |
'-' => 'red', |
|
195 |
); |
|
196 |
|
|
197 |
Text::Diff::diff($text_a, $text_b, { OUTPUT => sub { |
|
198 |
for (split /\n/, $_[0]) { |
|
199 |
print colored($_, $colors{substr($_, 0, 1)}), $/; |
|
200 |
} |
|
201 |
}}); |
|
174 | 202 |
} |
175 | 203 |
|
176 | 204 |
sub usage { |
... | ... | |
297 | 325 |
you debug schema awareness of the RDBO layer. |
298 | 326 |
|
299 | 327 |
=item C<--no-commit, -n> |
328 |
=item C<--dry-run> |
|
300 | 329 |
|
301 | 330 |
Do not write back generated files. This will do everything as usual but not |
302 | 331 |
actually modify any files. |
303 | 332 |
|
333 |
=item C<--diff> |
|
334 |
|
|
335 |
Displays diff for selected file, if file is present and never file is |
|
336 |
different. bware, does not imply C<no-commit>. |
|
337 |
|
|
304 | 338 |
=item C<--help, -h> |
305 | 339 |
|
306 | 340 |
Print this help. |
Auch abrufbar als: Unified diff
rose_auto_create_model: --diff, --dry-run alias für -n