From: Naeem Model Date: Tue, 15 Jul 2025 03:32:53 +0000 (+0000) Subject: Add option to group files/URIs X-Git-Url: https://git.nmode.ca/Fey/commitdiff_plain/a36e9479b2f84cc9b4e5b92e304ca2fac8ac8608?ds=sidebyside Add option to group files/URIs --- diff --git a/lib/App/Fey.pm b/lib/App/Fey.pm index c0778ab..5b9206c 100644 --- a/lib/App/Fey.pm +++ b/lib/App/Fey.pm @@ -29,7 +29,9 @@ sub launch { die "No files or URIs specified.\n" unless @_; - if ($options->{single}) { + if ($options->{group}) { + $self->_launch_group($options, @_); + } elsif ($options->{single}) { $self->_launch_single($options, @_); } else { $self->_launch($options, @_); @@ -57,6 +59,37 @@ sub _launch { } } +sub _launch_group { + my $self = shift; + my $options = shift; + + my ($groups, $handlers) = ({}, {}); + for my $file_or_uri (@_) { + my $handler = $self->_get_handler($file_or_uri); + if ($handler) { + $groups->{"$handler"} //= []; + push @{ $groups->{"$handler"} }, $file_or_uri; + $handlers->{"$handler"} = $handler; + } + } + + if ($options->{fork}) { + for my $group (keys %{ $groups }) { + if ($options->{fork}) { + my $pid = fork; + next if $pid; + } + + $handlers->{$group}->(@{ $groups->{$group} }); + return; + } + } else { + for my $group (keys %{ $groups }) { + $handlers->{$group}->(@{ $groups->{$group} }); + } + } +} + sub _launch_single { my $self = shift; my $options = shift; diff --git a/script/fey b/script/fey index bba93c7..a612187 100644 --- a/script/fey +++ b/script/fey @@ -8,11 +8,13 @@ use App::Fey qw(fey); my $options = { fork => 0, + group => 0, single => 0 }; GetOptions( 'f|fork' => \$options->{fork}, + 'g|group' => \$options->{group}, 's|single' => \$options->{single} );