Skip to content

Commit

Permalink
options -h/--help should not exit with failure
Browse files Browse the repository at this point in the history
  • Loading branch information
DrYak authored and SoapZA committed Nov 16, 2017
1 parent cac04c1 commit 1c290b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/shorah/b2w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ int main(int argc, char* argv[])
tmp.max = atof(optarg);
break;
case 'h':
fprintf(stdout, "%s", help_string);
exit(EXIT_SUCCESS);
default:
fprintf(stderr, "%s", help_string);
return 1;
exit(EXIT_FAILURE);
}
}
if (argc < 11 || argc > 12) {
Expand Down Expand Up @@ -306,5 +309,5 @@ int main(int argc, char* argv[])
samclose(tmp.in);
covOut.close();
tmp.reads.close();
return 0;
exit(EXIT_SUCCESS);
}
6 changes: 3 additions & 3 deletions src/shorah/contain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ struct Read
std::string seq;
};

void help(void)
void help(const int exit_code = EXIT_FAILURE)
{
std::cout << "Usage: contain -f basename\n";
std::cout << "Expects basename.read, outputs basename.rest\n";
exit(1);
exit(exit_code);
}

void getReads(std::istream& infile, std::vector<Read>& ans)
Expand Down Expand Up @@ -154,7 +154,7 @@ int main(int argc, char** argv)
help();
break;
case 'h':
help();
help(EXIT_SUCCESS);
break;
default:
help();
Expand Down
6 changes: 4 additions & 2 deletions src/shorah/dpm_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ int parsecommandline(int argc, char** argv)

char c;
while ((c = getopt(argc, argv, "i:j:a:t:o:m:K:k:R:c:Hh")) != -1) {

int exit_code = EXIT_FAILURE;
switch (c) {
case 'i':
filein = optarg;
Expand Down Expand Up @@ -2189,6 +2189,8 @@ int parsecommandline(int argc, char** argv)
case 'R':
randseed = atoi(optarg);
break;
case 'h':
exit_code = EXIT_SUCCESS;
default:
fprintf(stdout,
"%s [options]\n"
Expand All @@ -2205,7 +2207,7 @@ int parsecommandline(int argc, char** argv)
"-----------------------------------------------------\n"
"\t-h\t\t this help!\n",
argv[0]);
exit(-1);
exit(exit_code);
}
}
if (HISTORY > iter) HISTORY = iter;
Expand Down
6 changes: 3 additions & 3 deletions src/shorah/freqEst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ double EM(std::vector<double>& newP, std::vector<std::vector<double> > const& Z,
}
return newEll;
}
void help(void)
void help(const int exit_code = EXIT_FAILURE)
{
std::cout << "Usage: freqEst -f basename [-p precision -i maxiter -r runs -h -k kill -?]\n";
std::cout << "Expects basename.read and basename.geno\n";
std::cout << "Outputs to basename.popl\n";
exit(1);
exit(exit_code);
}

int main(int argc, char** argv)
Expand Down Expand Up @@ -439,7 +439,7 @@ int main(int argc, char** argv)
help();
break;
case 'h':
help();
help(EXIT_SUCCESS);
break;
default:
help();
Expand Down

0 comments on commit 1c290b4

Please sign in to comment.