summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosias <me@josias.dev>2021-07-20 10:17:57 -0700
committerJosias <me@josias.dev>2021-07-20 10:24:15 -0700
commit322fc27f332379971764881a0eec412423982435 (patch)
tree8f4d401019dfa1484a7677d77a49eaea56710a2b
parent782cb6cd857205dcbb32d84b66bcb22cb7051dfd (diff)
Differentiate lacking arguments and command not found
Previously the same generic error would occur if a notebook command was incomplete and if the command was not found. Now jw returns distinct errors and displays usage information.
-rw-r--r--main.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/main.c b/main.c
index 7203bb2..c4cae62 100644
--- a/main.c
+++ b/main.c
@@ -80,14 +80,25 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
+ const char *notebook_commands[] = { "new", "search", "post" };
+ bool is_notebook_command = false;
+ for (size_t i = 0; i < 3; ++i) {
+ if (strcmp(notebook_commands[i], argv[1]) == 0) {
+ is_notebook_command = true;
+ }
+ }
+
if (strcmp(argv[1], "help") == 0) {
print_help();
return EXIT_SUCCESS;
} else if (strcmp(argv[1], "version") == 0) {
print_version_info();
return EXIT_SUCCESS;
- } else if (argc < 3) {
- fprintf(stderr, "jw: command %s doesn't exist or needs argument\n", argv[1]);
+ } else if (argc < 3 && is_notebook_command == true) {
+ fprintf(stderr, "Usage: jw %s NOTEBOOK\n", argv[1]);
+ return EXIT_FAILURE;
+ } else {
+ fprintf(stderr, "jw: command \"%s\" not found\n", argv[1]);
return EXIT_FAILURE;
}