js generator: move finding sources into method

less code directly executed in the global execution path makes the
sources a bit easier to grasp and reason about.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-05-09 09:01:16 +02:00
parent 7b7a7598c0
commit 2bcbc73300

View File

@ -44,22 +44,25 @@ if (my $base = $options->{b}) {
} }
} }
my $sources = []; sub find_js_sources {
my ($base_dirs) = @_;
my $find_cmd = 'find '; my $find_cmd = 'find ';
# shell quote heuristic, with the (here safe) assumption that the dirs don't contain single-quotes # shell quote heuristic, with the (here safe) assumption that the dirs don't contain single-quotes
$find_cmd .= join(' ', map { "'$_'" } $dirs->@*); $find_cmd .= join(' ', map { "'$_'" } $base_dirs->@*);
$find_cmd .= ' -name "*.js"'; $find_cmd .= ' -name "*.js"';
open(my $find_cmd_output, '-|', "$find_cmd | sort") or die "Failed to execute command: $!"; open(my $find_cmd_output, '-|', "$find_cmd | sort") or die "Failed to execute command: $!";
# Iterate through the sorted output line by line my $sources = [];
while (my $line = <$find_cmd_output>) { while (my $line = <$find_cmd_output>) {
chomp $line; chomp $line;
print "F: $line\n"; print "F: $line\n";
push @$sources, $line; push @$sources, $line;
} }
close($find_cmd_output); close($find_cmd_output);
return $sources;
}
my $header = <<__EOD; my $header = <<__EOD;
Proxmox message catalog. Proxmox message catalog.
@ -125,6 +128,8 @@ sub extract_msg {
if !$count; if !$count;
} }
my $sources = find_js_sources($dirs);
foreach my $s (@$sources) { foreach my $s (@$sources) {
open(my $SRC_FH, '<', $s) || die "unable to open file '$s' - $!\n"; open(my $SRC_FH, '<', $s) || die "unable to open file '$s' - $!\n";
while(defined(my $line = <$SRC_FH>)) { while(defined(my $line = <$SRC_FH>)) {