]> nmode's Git Repositories - Fey/commitdiff
Add option to group files/URIs
authorNaeem Model <me@nmode.ca>
Tue, 15 Jul 2025 03:32:53 +0000 (03:32 +0000)
committerNaeem Model <me@nmode.ca>
Tue, 15 Jul 2025 03:32:53 +0000 (03:32 +0000)
lib/App/Fey.pm
script/fey

index c0778ab2ede342c99b79f96f124388ab303f3310..5b9206cf02fc978f7f0bf2e413616318e80ec7ab 100644 (file)
@@ -29,7 +29,9 @@ sub launch {
 
     die "No files or URIs specified.\n" unless @_;
 
 
     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, @_);
         $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;
 sub _launch_single {
     my $self = shift;
     my $options = shift;
index bba93c7fb37e984e49805328c75fa5676ccb8acc..a612187d71871fc81b592b00dab9056573c2a36f 100644 (file)
@@ -8,11 +8,13 @@ use App::Fey qw(fey);
 
 my $options = {
     fork => 0,
 
 my $options = {
     fork => 0,
+    group => 0,
     single => 0
 };
 
 GetOptions(
     'f|fork' => \$options->{fork},
     single => 0
 };
 
 GetOptions(
     'f|fork' => \$options->{fork},
+    'g|group' => \$options->{group},
     's|single' => \$options->{single}
 );
 
     's|single' => \$options->{single}
 );