Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Commit

Permalink
Add '-x' option for halting on failure
Browse files Browse the repository at this point in the history
It is useful for repeatedly running commands that are not expected
to fail but require investigation upon failure.
  • Loading branch information
jvirtanen committed Jun 8, 2012
1 parent 31ee09f commit a82e983
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/watch.c
Expand Up @@ -37,6 +37,11 @@

static int quiet = 0;

/*
* Halt on failure.
*/
static int halt = 0;

/*
* Output command usage.
*/
Expand All @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a82e983

Please sign in to comment.