]> nmode's Git Repositories - Fey/commitdiff
Allow reading files/URIs from STDIN
authorNaeem Model <me@nmode.ca>
Thu, 17 Jul 2025 03:28:45 +0000 (03:28 +0000)
committerNaeem Model <me@nmode.ca>
Thu, 17 Jul 2025 03:28:45 +0000 (03:28 +0000)
lib/App/Fey.pm
script/fey

index 7b287f07e185cfeeb2ca1d70adcbbfa923842e7a..8b802a0d70e7a1881af2e3bcf1baae2a074a7051 100644 (file)
@@ -27,6 +27,13 @@ sub launch {
     my $self = shift;
     my $options = ref $_[0] ? shift : {};
 
     my $self = shift;
     my $options = ref $_[0] ? shift : {};
 
+    if (!(-t STDIN)) {
+        _read_stdin(\@_);
+    }
+    if (!@_ || $options->{interactive}) {
+        open STDIN, '<', '/dev/tty'; 
+        _read_stdin(\@_);
+    }
     die "No files or URIs specified.\n" unless @_;
 
     if ($options->{group}) {
     die "No files or URIs specified.\n" unless @_;
 
     if ($options->{group}) {
@@ -129,6 +136,13 @@ sub _get_handler {
     }
 }
 
     }
 }
 
+sub _read_stdin {
+    for my $file_or_uri (<STDIN>) {
+        chomp $file_or_uri;
+        push @{ $_[0] }, $file_or_uri;
+    }
+}
+
 sub fey {
     App::Fey->new(ref $_[0] ? $_[0] : {})->launch(@_);
 }
 sub fey {
     App::Fey->new(ref $_[0] ? $_[0] : {})->launch(@_);
 }
index 69eca68a6bef2e525c7e213f65b5c423b7cf0edf..490366d8d5ad02e465eeb12838b6b5f015902c65 100644 (file)
@@ -10,6 +10,7 @@ my $options = {
     context => undef,
     fork => 0,
     group => 0,
     context => undef,
     fork => 0,
     group => 0,
+    interactive => 0,
     single => 0
 };
 
     single => 0
 };
 
@@ -17,6 +18,7 @@ GetOptions(
     'c|context:s' => \$options->{context},
     'f|fork' => \$options->{fork},
     'g|group' => \$options->{group},
     'c|context:s' => \$options->{context},
     'f|fork' => \$options->{fork},
     'g|group' => \$options->{group},
+    'i|interactive' => \$options->{interactive},
     's|single' => \$options->{single}
 );
 
     's|single' => \$options->{single}
 );