Permalink
Browse files

Add '-x' option for halting on failure

It is useful for repeatedly running commands that are not expected
to fail but require investigation upon failure.
  • Loading branch information...
1 parent 31ee09f commit a82e983c44c4a78a3932896a87434288c4b86002 @jvirtanen jvirtanen committed Jun 8, 2012
Showing with 15 additions and 0 deletions.
  1. +1 −0 Readme.md
  2. +14 −0 src/watch.c
View
@@ -12,6 +12,7 @@ Usage: watch [options] <cmd>
Options:
-q, --quiet only output stderr
+ -x, --halt halt on failure
-i, --interval <n> interval in seconds or ms defaulting to 1
-v, --version output version number
View
@@ -38,6 +38,11 @@
static int quiet = 0;
/*
+ * Halt on failure.
+ */
+static int halt = 0;
+
+/*
* Output command usage.
*/
@@ -50,6 +55,7 @@ usage() {
" Options:\n"
"\n"
" -q, --quiet only output stderr\n"
+ " -x, --halt halt on failure\n"
" -i, --interval <n> interval in seconds or ms defaulting to 1\n"
" -v, --version output version number\n"
" -h, --help output this help information\n"
@@ -159,6 +165,12 @@ main(int argc, const char **argv){
continue;
}
+ // -x, --halt
+ if (option("-x", "--halt", arg)) {
+ halt = 1;
+ continue;
+ }
+
// -v, --version
if (option("-v", "--version", arg)) {
printf("%s\n", VERSION);
@@ -224,6 +236,8 @@ main(int argc, const char **argv){
// exit > 0
if (WEXITSTATUS(status)) {
fprintf(stderr, "\033[90mexit: %d\33[0m\n\n", WEXITSTATUS(status));
+
+ if (halt) exit(WEXITSTATUS(status));
}
mssleep(interval);

0 comments on commit a82e983

Please sign in to comment.