Skip to content

Commit

Permalink
fix return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Deitch committed Sep 26, 2017
1 parent 8d368aa commit 4f7fc4f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "diff.h"

void printHelp();
const char *version = "1.0.4";
const char *version = "1.0.5";

int main(int argc, char *argv[]) {
extern char *optarg;
Expand Down Expand Up @@ -78,13 +78,13 @@ int main(int argc, char *argv[]) {
break;
case 'h':
printHelp();
exit(1);
return 0;
}
}

if (optind == 1) {
printHelp();
exit(1);
return 1;
}

if (H == 0) {
Expand All @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
}
setup(connection);
printf("Setup successful\n");
return 1;
return 0;
}

if (is_setup == 0) {
Expand All @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) {

if (s) {
getLatest(connection, 20);
return 1;
return 0;
}

if (u + d == 0) {
Expand All @@ -124,29 +124,30 @@ int main(int argc, char *argv[]) {

if (d) {
rollbackMigrations(connection, p);
return 1;
return 0;
}

if (u) {
if (argv[optind] == NULL) {
fprintf(stderr, "No directory provided\n");
exit(1);
return 1;
}
char *file = argv[optind];
char path[PATH_MAX];
realpath(file, path);
DIR *dir = opendir(path);
if (!dir) {
fprintf(stderr, "No valid directory provided: %s\n", path);
exit(1);
return 1;
}
closedir(dir);
char **migrationToBeRan = missing_from_db(getMigrationsFromDb(connection), getMigrationsFromFs(path));
if (strcmp(migrationToBeRan[0], "\0") == 0) {
printf("Nothing to migrate\n");
return 1;
return 0;
}
runMigrations(connection, migrationToBeRan, p);
return 0;
}

return 1;
Expand Down

0 comments on commit 4f7fc4f

Please sign in to comment.