Skip to content

Commit

Permalink
When commandline switch is 'help' we should not exit with error
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Viera committed Sep 22, 2023
1 parent 6d3e044 commit 8f1eee1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions eatmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ArgParser* configure_cmd() {
return parser;
}

void help() {
void print_help() {
printf("eatmemory %s - %s\n\n", VERSION, "https://github.com/julman99/eatmemory");
printf("Usage: eatmemory [-t <seconds>] <size>\n");
printf("Size can be specified in megabytes or gigabytes in the following way:\n");
Expand All @@ -54,7 +54,6 @@ void help() {
printf("Options:\n");
printf("-t <seconds> Exit after specified number of seconds\n");
printf("\n");
exit(1);
}

bool eat(long total,int chunk){
Expand All @@ -78,8 +77,13 @@ int main(int argc, char *argv[]){

ArgParser* parser = configure_cmd();
ap_parse(parser, argc, argv);
if(ap_found(parser, "help") || ap_count_args(parser) != 1) {
help();
if(ap_found(parser, "help")) {
print_help();
exit(0);
}
if(ap_count_args(parser) != 1) {
print_help();
exit(1);
}

int timeout = ap_get_int_value(parser, "timeout");
Expand Down

0 comments on commit 8f1eee1

Please sign in to comment.