Skip to content

Commit

Permalink
Stop parameter parsing after the first non-option
Browse files Browse the repository at this point in the history
Signed-off-by: Tj Holowaychuk <tj@vision-media.ca>
  • Loading branch information
theomega authored and tj committed Dec 14, 2011
1 parent 81e98c4 commit 0139c80
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/watch.c
Expand Up @@ -116,27 +116,28 @@ main(int argc, const char **argv){

int len = 0;
char *args[ARGS_MAX];
unsigned int parseOptions = 1;

for (int i = 1; i < argc; ++i) {
const char *arg = argv[i];

// -h, --help
if (option("-h", "--help", arg)) usage();
if (parseOptions && option("-h", "--help", arg)) usage();

// -q, --quiet
if (option("-q", "--quiet", arg)) {
if (parseOptions && option("-q", "--quiet", arg)) {
quiet = 1;
continue;
}

// -V, --version
if (option("-v", "--version", arg)) {
if (parseOptions && option("-v", "--version", arg)) {
printf("%s\n", VERSION);
exit(1);
}

// -i, --interval <n>
if (option("-i", "--interval", arg)) {
if (parseOptions && option("-i", "--interval", arg)) {
if (argc-1 == i) {
fprintf(stderr, "\n --interval requires an argument\n\n");
exit(1);
Expand All @@ -157,6 +158,7 @@ main(int argc, const char **argv){
}

args[len++] = (char *) arg;
parseOptions = 0;
}

// <cmd>
Expand Down

0 comments on commit 0139c80

Please sign in to comment.