diff options
author | Josias <me@josias.dev> | 2021-07-29 11:58:27 -0700 |
---|---|---|
committer | Josias <me@josias.dev> | 2021-07-29 11:58:27 -0700 |
commit | abccb7bed44f8eb6fbebd44507bccc0d447a99d0 (patch) | |
tree | 703053206ef28e60ff4797695b449511274385f2 | |
parent | 6d9462818399525b11633255d53bc62f079717e7 (diff) |
Fix loading notebooks
Instead of comparing the number for the error code, it compared
the pointer, which always erred.
-rw-r--r-- | main.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -83,10 +83,10 @@ struct notebook open_notebook(const char *notebook_id, int *err) { if (stat(notebook.path, &st) == -1) exists = false; - if (exists) { + if (exists && *err != 0) { fprintf(stderr, "Error opening notebook %s. Make sure notebook.yaml is available\n", notebook_id); *err = -1; - } else { + } else if (!exists) { fprintf(stderr, "Notebook %s does not exist. Create it with `jw new %s`\n", notebook_id, notebook_id); *err = -1; } @@ -111,10 +111,15 @@ int main(int argc, char **argv) int err = 0; if (strcmp(argv[1], "new") == 0) { + if (argc < 3) { + fprintf(stderr, "Usage: jw new NOTEBOOK\n"); + return EXIT_FAILURE; + } err = notebook_new(argv[2]); if (err != 0) { - if (err == -1) + if (err == -1) { fprintf(stderr, "Notebook already exists\n"); + } fprintf(stderr, "Failed to make notebook: %s\n", argv[2]); return EXIT_FAILURE; } |