Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add '-x' option for halting on failure #11

Merged
merged 4 commits into from

2 participants

@jvirtanen

It is useful for repeatedly running commands that are not expected to fail but require investigation upon failure.

jvirtanen added some commits
@jvirtanen jvirtanen Add 'make all' target
It is useful for forcing a rebuild with 'make clean all'.
137a46a
@jvirtanen jvirtanen Silence warnings
Both Clang 2.1 and GCC 4.2.1 warn about using an assignment as a
boolean condition without wrapping it into parentheses.
be0537f
@jvirtanen jvirtanen Fix '-v' option documentation 31ee09f
@jvirtanen jvirtanen 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.
a82e983
@tj tj merged commit 00951fb into tj:master
@tj
Owner
tj commented

great thanks!

@jvirtanen

Thanks! Keep up the great projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 8, 2012
  1. @jvirtanen

    Add 'make all' target

    jvirtanen authored
    It is useful for forcing a rebuild with 'make clean all'.
  2. @jvirtanen

    Silence warnings

    jvirtanen authored
    Both Clang 2.1 and GCC 4.2.1 warn about using an assignment as a
    boolean condition without wrapping it into parentheses.
  3. @jvirtanen
  4. @jvirtanen

    Add '-x' option for halting on failure

    jvirtanen authored
    It is useful for repeatedly running commands that are not expected
    to fail but require investigation upon failure.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 5 deletions.
  1. +3 −1 Makefile
  2. +2 −1  Readme.md
  3. +17 −3 src/watch.c
View
4 Makefile
@@ -2,6 +2,8 @@
CFLAGS = -std=c99 -D_POSIX_C_SOURCE=199309L -Wall -pedantic
PREFIX ?= /usr/local
+all: watch
+
watch: src/watch.c
$(CC) $< $(CFLAGS) -o $@
@@ -14,4 +16,4 @@ uninstall:
clean:
rm -f watch
-.PHONY: clean install uninstall
+.PHONY: all clean install uninstall
View
3  Readme.md
@@ -12,8 +12,9 @@ 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
+ -v, --version output version number
```
View
20 src/watch.c
@@ -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"
@@ -113,7 +119,7 @@ int
length(char **strs) {
int n = 0;
char *str;
- while (str = *strs++) n += strlen(str);
+ while ((str = *strs++)) n += strlen(str);
return n + 1;
}
@@ -126,7 +132,7 @@ join(char **strs, int len, char *val) {
--len;
char *buf = malloc(length(strs) + len * strlen(val));
char *str;
- while (str = *strs++) {
+ while ((str = *strs++)) {
strcat(buf, str);
if (*strs) strcat(buf, val);
}
@@ -159,7 +165,13 @@ main(int argc, const char **argv){
continue;
}
- // -V, --version
+ // -x, --halt
+ if (option("-x", "--halt", arg)) {
+ halt = 1;
+ continue;
+ }
+
+ // -v, --version
if (option("-v", "--version", arg)) {
printf("%s\n", VERSION);
exit(1);
@@ -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);
Something went wrong with that request. Please try again.