Bläddra i källkod

Provide a one-shot mode for programatic access to current state data

Zachary Kotlarek 9 år sedan
förälder
incheckning
f2ef6ce714
1 ändrade filer med 18 tillägg och 3 borttagningar
  1. 18 3
      dmx/debug.pl

+ 18 - 3
dmx/debug.pl

@@ -2,9 +2,6 @@
 use strict;
 use warnings;
 
-# Always debug
-BEGIN { $ENV{'DEBUG'} = 1; }
-
 # Local modules
 use Cwd qw(abs_path);
 use File::Basename qw(dirname);
@@ -18,6 +15,14 @@ my $DELAY = 10;
 # App config
 my $STATE_SOCK = 'DEBUG';
 
+# Allow one-shot mode or force debug
+my $KEY = undef();
+if (scalar(@ARGV) > 0) {
+	$KEY = $ARGV[0];
+} else {
+	DMX::debug(1);
+}
+
 # Sockets
 DMX::stateSocket($STATE_SOCK);
 DMX::stateSubscribe($STATE_SOCK);
@@ -30,6 +35,16 @@ while (1) {
 
 	if ($state) {
 
+		# One-shot mode
+		if (defined($KEY)) {
+			if (exists($exists{$KEY})) {
+				print $exists{$KEY} . '@' . $mtime{$KEY} . "\n";
+			} else {
+				print STDERR 'No such element: ' . $KEY . "\n";
+			}
+			exit 0;
+		}
+
 		# Find the latest modification timestamp
 		my $file = undef();
 		foreach my $key (keys(%mtime)) {