aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryson Steck <brysonsteck@protonmail.com>2022-10-17 15:28:28 -0600
committerBryson Steck <brysonsteck@protonmail.com>2022-10-17 15:28:28 -0600
commit38eb8c9b4720e804c477b0c5345b0beb03d088f1 (patch)
tree70824b7507e5562a416933a5b16809bd5c134a67
parent0c6c5eff51009beda72717351abd442b07f4e0e3 (diff)
downloadlisten-38eb8c9b4720e804c477b0c5345b0beb03d088f1.tar
listen-38eb8c9b4720e804c477b0c5345b0beb03d088f1.tar.gz
listen-38eb8c9b4720e804c477b0c5345b0beb03d088f1.tar.bz2
implement timeout flag, flag checking
-rwxr-xr-xlisten44
1 files changed, 35 insertions, 9 deletions
diff --git a/listen b/listen
index 11c2fc3..886dfb3 100755
--- a/listen
+++ b/listen
@@ -1,7 +1,5 @@
#!/usr/bin/env perl
# TODO:
-# implement -r flag
-# implement --timeout flag in main loop
# possibly create a man page
#
# listen: a simple configurable build system
@@ -52,7 +50,7 @@ sub flags {
foreach $arg (@ARGV) {
# shorthand args
- if ($arg =~ m/-[aosrhv]/) {
+ if ($arg =~ m/^-[aosrhv]+$/) {
if ($arg =~ m/a/) {
$ALL_FLAG = "def";
}
@@ -146,6 +144,13 @@ sub flags {
$ANY_FLAG = "def";
} elsif ($arg =~ m/--run/) {
$RUN_FLAG = "def";
+ # at this point, either it is an unknown flag or the start of the filename(s)
+ } elsif ($arg =~ m/^-[^aosrhv]+$/) {
+ print "listen: Unknown flag: $arg\n";
+ exit 2;
+ } elsif ($arg =~ m/^--[a-z]/) {
+ print "listen: Unknown flag: $arg\n";
+ exit 2;
} else {
last;
}
@@ -323,7 +328,13 @@ sub start {
# if output differs, mark as modified
foreach $modified (@modified_files) {
if (@current_epoch[$counter] != @previous_epoch[$counter]) {
- $modified = "yes";
+ if ($TIMEOUT) {
+ if (!($current_epoch[$counter] - $previous_epoch[$counter] <= $TIMEOUT)) {
+ $modified = "yes";
+ }
+ } else {
+ $modified = "yes";
+ }
}
$counter++;
}
@@ -342,9 +353,17 @@ sub start {
# if output differs, run command
foreach (@current_epoch) {
if ($current_epoch[$counter] != $previous_epoch[$counter]) {
- $run = "def";
- $file_changed = $counter;
- last;
+ if ($TIMEOUT) {
+ if (!($current_epoch[$counter] - $previous_epoch[$counter] <= $TIMEOUT)) {
+ $run = "def";
+ $file_changed = $counter;
+ last;
+ }
+ } else {
+ $run = "def";
+ $file_changed = $counter;
+ last;
+ }
}
$counter++;
}
@@ -352,8 +371,15 @@ sub start {
# logic for singular files
} else {
if ($current_epoch[0] != $previous_epoch[0]) {
- $run = "def";
- $file_changed = 0;
+ if ($TIMEOUT) {
+ if (!($current_epoch[0] - $previous_epoch[0] <= $TIMEOUT)) {
+ $run = "def";
+ $file_changed = 0;
+ }
+ } else {
+ $run = "def";
+ $file_changed = 0;
+ }
}
}